Author: cfinck
Date: Wed Jan 6 05:15:44 2016
New Revision: 70505
URL:
http://svn.reactos.org/svn/reactos?rev=70505&view=rev
Log:
[WINSPOOL]
- Implement StartDocPrinterA.
- Fix an uninitialized access in StartDocPrinterW.
- Make OpenPrinterA and StartDocPrinterA consistent.
Modified:
branches/colins-printing-for-freedom/reactos/win32ss/printing/base/winspool/printers.c
Modified:
branches/colins-printing-for-freedom/reactos/win32ss/printing/base/winspool/printers.c
URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
==============================================================================
---
branches/colins-printing-for-freedom/reactos/win32ss/printing/base/winspool/printers.c [iso-8859-1]
(original)
+++
branches/colins-printing-for-freedom/reactos/win32ss/printing/base/winspool/printers.c [iso-8859-1]
Wed Jan 6 05:15:44 2016
@@ -379,24 +379,23 @@
OpenPrinterA(LPSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSA pDefault)
{
BOOL bReturnValue = FALSE;
+ DWORD cch;
PWSTR pwszPrinterName = NULL;
- PWSTR pwszDatatype = NULL;
PRINTER_DEFAULTSW wDefault = { 0 };
- size_t StringLength;
if (pPrinterName)
{
// Convert pPrinterName to a Unicode string pwszPrinterName
- StringLength = strlen(pPrinterName) + 1;
-
- pwszPrinterName = HeapAlloc(hProcessHeap, 0, StringLength * sizeof(WCHAR));
+ cch = strlen(pPrinterName);
+
+ pwszPrinterName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
if (!pwszPrinterName)
{
ERR("HeapAlloc failed for pwszPrinterName with last error %lu!\n",
GetLastError());
goto Cleanup;
}
- MultiByteToWideChar(CP_ACP, 0, pPrinterName, -1, pwszPrinterName, StringLength);
+ MultiByteToWideChar(CP_ACP, 0, pPrinterName, -1, pwszPrinterName, cch + 1);
}
if (pDefault)
@@ -405,18 +404,17 @@
if (pDefault->pDatatype)
{
- // Convert pDefault->pDatatype to a Unicode string pwszDatatype that later
becomes wDefault.pDatatype
- StringLength = strlen(pDefault->pDatatype) + 1;
-
- pwszDatatype = HeapAlloc(hProcessHeap, 0, StringLength * sizeof(WCHAR));
- if (!pwszDatatype)
+ // Convert pDefault->pDatatype to a Unicode string wDefault.pDatatype
+ cch = strlen(pDefault->pDatatype);
+
+ wDefault.pDatatype = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
+ if (!wDefault.pDatatype)
{
- ERR("HeapAlloc failed for pwszDatatype with last error %lu!\n",
GetLastError());
+ ERR("HeapAlloc failed for wDefault.pDatatype with last error
%lu!\n", GetLastError());
goto Cleanup;
}
- MultiByteToWideChar(CP_ACP, 0, pDefault->pDatatype, -1, pwszDatatype,
StringLength);
- wDefault.pDatatype = pwszDatatype;
+ MultiByteToWideChar(CP_ACP, 0, pDefault->pDatatype, -1,
wDefault.pDatatype, cch + 1);
}
if (pDefault->pDevMode)
@@ -426,14 +424,14 @@
bReturnValue = OpenPrinterW(pwszPrinterName, phPrinter, &wDefault);
Cleanup:
+ if (wDefault.pDatatype)
+ HeapFree(hProcessHeap, 0, wDefault.pDatatype);
+
if (wDefault.pDevMode)
HeapFree(hProcessHeap, 0, wDefault.pDevMode);
if (pwszPrinterName)
HeapFree(hProcessHeap, 0, pwszPrinterName);
-
- if (pwszDatatype)
- HeapFree(hProcessHeap, 0, pwszDatatype);
return bReturnValue;
}
@@ -537,11 +535,97 @@
}
DWORD WINAPI
+StartDocPrinterA(HANDLE hPrinter, DWORD Level, PBYTE pDocInfo)
+{
+ DOC_INFO_1W wDocInfo1 = { 0 };
+ DWORD cch;
+ DWORD dwErrorCode;
+ DWORD dwReturnValue = 0;
+ PDOC_INFO_1A pDocInfo1 = (PDOC_INFO_1A)pDocInfo;
+
+ // Only check the minimum required for accessing pDocInfo.
+ // Additional sanity checks are done in StartDocPrinterW.
+ if (!pDocInfo1)
+ {
+ dwErrorCode = ERROR_INVALID_PARAMETER;
+ goto Cleanup;
+ }
+
+ if (Level != 1)
+ {
+ dwErrorCode = ERROR_INVALID_LEVEL;
+ goto Cleanup;
+ }
+
+ if (pDocInfo1->pDatatype)
+ {
+ // Convert pDocInfo1->pDatatype to a Unicode string wDocInfo1.pDatatype
+ cch = strlen(pDocInfo1->pDatatype);
+
+ wDocInfo1.pDatatype = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
+ if (!wDocInfo1.pDatatype)
+ {
+ ERR("HeapAlloc failed for wDocInfo1.pDatatype with last error
%lu!\n", GetLastError());
+ goto Cleanup;
+ }
+
+ MultiByteToWideChar(CP_ACP, 0, pDocInfo1->pDatatype, -1, wDocInfo1.pDatatype,
cch + 1);
+ }
+
+ if (pDocInfo1->pDocName)
+ {
+ // Convert pDocInfo1->pDocName to a Unicode string wDocInfo1.pDocName
+ cch = strlen(pDocInfo1->pDocName);
+
+ wDocInfo1.pDocName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
+ if (!wDocInfo1.pDocName)
+ {
+ ERR("HeapAlloc failed for wDocInfo1.pDocName with last error
%lu!\n", GetLastError());
+ goto Cleanup;
+ }
+
+ MultiByteToWideChar(CP_ACP, 0, pDocInfo1->pDocName, -1, wDocInfo1.pDocName,
cch + 1);
+ }
+
+ if (pDocInfo1->pOutputFile)
+ {
+ // Convert pDocInfo1->pOutputFile to a Unicode string wDocInfo1.pOutputFile
+ cch = strlen(pDocInfo1->pOutputFile);
+
+ wDocInfo1.pOutputFile = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
+ if (!wDocInfo1.pOutputFile)
+ {
+ ERR("HeapAlloc failed for wDocInfo1.pOutputFile with last error
%lu!\n", GetLastError());
+ goto Cleanup;
+ }
+
+ MultiByteToWideChar(CP_ACP, 0, pDocInfo1->pOutputFile, -1,
wDocInfo1.pOutputFile, cch + 1);
+ }
+
+ dwReturnValue = StartDocPrinterW(hPrinter, Level, (PBYTE)&wDocInfo1);
+ dwErrorCode = GetLastError();
+
+Cleanup:
+ if (wDocInfo1.pDatatype)
+ HeapFree(hProcessHeap, 0, wDocInfo1.pDatatype);
+
+ if (wDocInfo1.pDocName)
+ HeapFree(hProcessHeap, 0, wDocInfo1.pDocName);
+
+ if (wDocInfo1.pOutputFile)
+ HeapFree(hProcessHeap, 0, wDocInfo1.pOutputFile);
+
+ SetLastError(dwErrorCode);
+ return dwReturnValue;
+}
+
+DWORD WINAPI
StartDocPrinterW(HANDLE hPrinter, DWORD Level, PBYTE pDocInfo)
{
DWORD cbAddJobInfo1;
DWORD cbNeeded;
DWORD dwErrorCode;
+ DWORD dwReturnValue = 0;
PADDJOB_INFO_1W pAddJobInfo1 = NULL;
PDOC_INFO_1W pDocInfo1 = (PDOC_INFO_1W)pDocInfo;
PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
@@ -611,14 +695,17 @@
}
if (dwErrorCode == ERROR_SUCCESS)
+ {
pHandle->bStartedDoc = TRUE;
+ dwReturnValue = pHandle->dwJobID;
+ }
Cleanup:
if (pAddJobInfo1)
HeapFree(hProcessHeap, 0, pAddJobInfo1);
SetLastError(dwErrorCode);
- return pHandle->dwJobID;
+ return dwReturnValue;
}
BOOL WINAPI