[PRINTING]

Fix all EnumPrintProcessorDatatypes API tests.

svn path=/trunk/; revision=75215
This commit is contained in:
Colin Finck 2017-06-27 07:25:04 +00:00
parent 26d220be5e
commit 20bbfa5624
4 changed files with 63 additions and 50 deletions

View file

@ -2,7 +2,7 @@
* PROJECT: ReactOS Spooler Router
* LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation
* PURPOSE: Functions related to Print Processors
* COPYRIGHT: Copyright 2015-2016 Colin Finck <colin@reactos.org>
* COPYRIGHT: Copyright 2015-2017 Colin Finck <colin@reactos.org>
*/
#include "precomp.h"
@ -10,8 +10,17 @@
BOOL WINAPI
EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
{
PSPOOLSS_PRINT_PROVIDER pPrintProvider;
// Sanity checks
if (cbBuf && !pDatatypes)
{
SetLastError(ERROR_INVALID_USER_BUFFER);
return FALSE;
}
// Always call this function on the Local Spooler.
PSPOOLSS_PRINT_PROVIDER pPrintProvider = CONTAINING_RECORD(PrintProviderList.Flink, SPOOLSS_PRINT_PROVIDER, Entry);
pPrintProvider = CONTAINING_RECORD(PrintProviderList.Flink, SPOOLSS_PRINT_PROVIDER, Entry);
return pPrintProvider->PrintProvider.fpEnumPrintProcessorDatatypes(pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned);
}

View file

@ -8,17 +8,21 @@
#include "precomp.h"
static void
_MarshallDownDatatypesInfo(PDATATYPES_INFO_1W pDatatypesInfo1)
_MarshallDownDatatypesInfo(PDATATYPES_INFO_1W* ppDatatypesInfo1)
{
// Replace absolute pointer addresses in the output by relative offsets.
PDATATYPES_INFO_1W pDatatypesInfo1 = *ppDatatypesInfo1;
pDatatypesInfo1->pName = (PWSTR)((ULONG_PTR)pDatatypesInfo1->pName - (ULONG_PTR)pDatatypesInfo1);
*ppDatatypesInfo1 += sizeof(DATATYPES_INFO_1W);
}
static void
_MarshallDownPrintProcessorInfo(PPRINTPROCESSOR_INFO_1W pPrintProcessorInfo1)
_MarshallDownPrintProcessorInfo(PPRINTPROCESSOR_INFO_1W* ppPrintProcessorInfo1)
{
// Replace absolute pointer addresses in the output by relative offsets.
PPRINTPROCESSOR_INFO_1W pPrintProcessorInfo1 = *ppPrintProcessorInfo1;
pPrintProcessorInfo1->pName = (PWSTR)((ULONG_PTR)pPrintProcessorInfo1->pName - (ULONG_PTR)pPrintProcessorInfo1);
*ppPrintProcessorInfo1 += sizeof(PRINTPROCESSOR_INFO_1W);
}
DWORD
@ -39,8 +43,7 @@ DWORD
_RpcEnumPrintProcessorDatatypes(WINSPOOL_HANDLE pName, WCHAR* pPrintProcessorName, DWORD Level, BYTE* pDatatypes, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned)
{
DWORD dwErrorCode;
DWORD i;
PBYTE p = pDatatypes;
PBYTE pDatatypesAligned;
dwErrorCode = RpcImpersonateClient(NULL);
if (dwErrorCode != ERROR_SUCCESS)
@ -49,20 +52,25 @@ _RpcEnumPrintProcessorDatatypes(WINSPOOL_HANDLE pName, WCHAR* pPrintProcessorNam
return dwErrorCode;
}
EnumPrintProcessorDatatypesW(pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned);
dwErrorCode = GetLastError();
pDatatypesAligned = AlignRpcPtr(pDatatypes, &cbBuf);
if (dwErrorCode == ERROR_SUCCESS)
if (EnumPrintProcessorDatatypesW(pName, pPrintProcessorName, Level, pDatatypesAligned, cbBuf, pcbNeeded, pcReturned))
{
// Replace absolute pointer addresses in the output by relative offsets.
DWORD i;
PDATATYPES_INFO_1W p = (PDATATYPES_INFO_1W)pDatatypesAligned;
for (i = 0; i < *pcReturned; i++)
{
_MarshallDownDatatypesInfo((PDATATYPES_INFO_1W)p);
p += sizeof(DATATYPES_INFO_1W);
}
_MarshallDownDatatypesInfo(&p);
}
else
{
dwErrorCode = GetLastError();
}
RpcRevertToSelf();
UndoAlignRpcPtr(pDatatypes, pDatatypesAligned, cbBuf, pcbNeeded);
return dwErrorCode;
}
@ -70,8 +78,6 @@ DWORD
_RpcEnumPrintProcessors(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, DWORD Level, BYTE* pPrintProcessorInfo, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned)
{
DWORD dwErrorCode;
DWORD i;
PBYTE p = pPrintProcessorInfo;
dwErrorCode = RpcImpersonateClient(NULL);
if (dwErrorCode != ERROR_SUCCESS)
@ -86,11 +92,11 @@ _RpcEnumPrintProcessors(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, DWORD Level,
if (dwErrorCode == ERROR_SUCCESS)
{
// Replace absolute pointer addresses in the output by relative offsets.
DWORD i;
PPRINTPROCESSOR_INFO_1W p = (PPRINTPROCESSOR_INFO_1W)pPrintProcessorInfo;
for (i = 0; i < *pcReturned; i++)
{
_MarshallDownPrintProcessorInfo((PPRINTPROCESSOR_INFO_1W)p);
p += sizeof(PRINTPROCESSOR_INFO_1W);
}
_MarshallDownPrintProcessorInfo(&p);
}
RpcRevertToSelf();

View file

@ -9,17 +9,21 @@
#include <prtprocenv.h>
static void
_MarshallUpDatatypesInfo(PDATATYPES_INFO_1W pDatatypesInfo1)
_MarshallUpDatatypesInfo(PDATATYPES_INFO_1W* ppDatatypesInfo1)
{
// Replace relative offset addresses in the output by absolute pointers.
PDATATYPES_INFO_1W pDatatypesInfo1 = *ppDatatypesInfo1;
pDatatypesInfo1->pName = (PWSTR)((ULONG_PTR)pDatatypesInfo1->pName + (ULONG_PTR)pDatatypesInfo1);
*ppDatatypesInfo1 += sizeof(DATATYPES_INFO_1W);
}
static void
_MarshallUpPrintProcessorInfo(PPRINTPROCESSOR_INFO_1W pPrintProcessorInfo1)
_MarshallUpPrintProcessorInfo(PPRINTPROCESSOR_INFO_1W* ppPrintProcessorInfo1)
{
// Replace relative offset addresses in the output by absolute pointers.
PPRINTPROCESSOR_INFO_1W pPrintProcessorInfo1 = *ppPrintProcessorInfo1;
pPrintProcessorInfo1->pName = (PWSTR)((ULONG_PTR)pPrintProcessorInfo1->pName + (ULONG_PTR)pPrintProcessorInfo1);
*ppPrintProcessorInfo1 += sizeof(PRINTPROCESSOR_INFO_1W);
}
BOOL WINAPI
@ -47,8 +51,13 @@ BOOL WINAPI
EnumPrintProcessorDatatypesW(PWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
{
DWORD dwErrorCode;
DWORD i;
PBYTE p = pDatatypes;
// Sanity checks
if (Level != 1)
{
dwErrorCode = ERROR_INVALID_LEVEL;
goto Cleanup;
}
// Do the RPC call
RpcTryExcept
@ -64,14 +73,14 @@ EnumPrintProcessorDatatypesW(PWSTR pName, LPWSTR pPrintProcessorName, DWORD Leve
if (dwErrorCode == ERROR_SUCCESS)
{
// Replace relative offset addresses in the output by absolute pointers.
DWORD i;
PDATATYPES_INFO_1W p = (PDATATYPES_INFO_1W)pDatatypes;
for (i = 0; i < *pcReturned; i++)
{
_MarshallUpDatatypesInfo((PDATATYPES_INFO_1W)p);
p += sizeof(DATATYPES_INFO_1W);
}
_MarshallUpDatatypesInfo(&p);
}
Cleanup:
SetLastError(dwErrorCode);
return (dwErrorCode == ERROR_SUCCESS);
}
@ -80,8 +89,6 @@ BOOL WINAPI
EnumPrintProcessorsW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
{
DWORD dwErrorCode;
DWORD i;
PBYTE p = pPrintProcessorInfo;
// Choose our current environment if the caller didn't give any.
if (!pEnvironment)
@ -100,12 +107,11 @@ EnumPrintProcessorsW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintP
if (dwErrorCode == ERROR_SUCCESS)
{
// Replace relative offset addresses in the output by absolute pointers.
DWORD i;
PPRINTPROCESSOR_INFO_1W p = (PPRINTPROCESSOR_INFO_1W)pPrintProcessorInfo;
for (i = 0; i < *pcReturned; i++)
{
_MarshallUpPrintProcessorInfo((PPRINTPROCESSOR_INFO_1W)p);
p += sizeof(PRINTPROCESSOR_INFO_1W);
}
_MarshallUpPrintProcessorInfo(&p);
}
SetLastError(dwErrorCode);

View file

@ -2,7 +2,7 @@
* PROJECT: ReactOS Standard Print Processor
* LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation
* PURPOSE: Main functions
* COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
* COPYRIGHT: Copyright 2015-2017 Colin Finck <colin@reactos.org>
*/
#include "precomp.h"
@ -112,7 +112,6 @@ EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level
{
DWORD cbDatatype;
DWORD dwDatatypeCount = 0;
DWORD dwErrorCode;
DWORD dwOffsets[_countof(_pwszDatatypes)];
PWSTR* pCurrentDatatype;
PDWORD pCurrentOffset = dwOffsets;
@ -121,10 +120,7 @@ EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level
// Sanity checks
if (Level != 1 || !pcbNeeded || !pcReturned)
{
dwErrorCode = ERROR_INVALID_PARAMETER;
goto Cleanup;
}
return FALSE;
// Count the required buffer size and the number of datatypes.
*pcbNeeded = 0;
@ -145,15 +141,15 @@ EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level
// Check if the supplied buffer is large enough.
if (cbBuf < *pcbNeeded)
{
dwErrorCode = ERROR_INSUFFICIENT_BUFFER;
goto Cleanup;
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
// Check if a buffer was supplied at all.
if (!pDatatypes)
{
dwErrorCode = ERROR_INVALID_PARAMETER;
goto Cleanup;
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
// Copy over all datatypes.
@ -161,11 +157,7 @@ EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level
PackStrings(_pwszDatatypes, pDatatypes, dwOffsets, &pDatatypes[*pcbNeeded]);
*pcReturned = dwDatatypeCount;
dwErrorCode = ERROR_SUCCESS;
Cleanup:
SetLastError(dwErrorCode);
return (dwErrorCode == ERROR_SUCCESS);
return TRUE;
}