Fix all EnumPrintProcessorDatatypes API tests.
svn path=/trunk/; revision=75215
* 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"
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);
}
#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
_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)
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;
}
_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)
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();
#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
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
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);
}
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)
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);
* 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"
{
DWORD cbDatatype;
DWORD dwDatatypeCount = 0;
- DWORD dwErrorCode;
DWORD dwOffsets[_countof(_pwszDatatypes)];
PWSTR* pCurrentDatatype;
PDWORD pCurrentOffset = dwOffsets;
// 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;
// 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.
PackStrings(_pwszDatatypes, pDatatypes, dwOffsets, &pDatatypes[*pcbNeeded]);
*pcReturned = dwDatatypeCount;
- dwErrorCode = ERROR_SUCCESS;
-
-Cleanup:
- SetLastError(dwErrorCode);
- return (dwErrorCode == ERROR_SUCCESS);
+ return TRUE;
}