Winspool expects NULLs to be preserved in ascii to unicode
conversions.
This commit is contained in:
parent
39f73a2203
commit
0987ae04f3
|
@ -104,6 +104,21 @@ static BOOL WINSPOOL_GetPrinterDriver(HANDLE hPrinter, LPWSTR pEnvironment,
|
||||||
DWORD Level, LPBYTE pDriverInfo,
|
DWORD Level, LPBYTE pDriverInfo,
|
||||||
DWORD cbBuf, LPDWORD pcbNeeded,
|
DWORD cbBuf, LPDWORD pcbNeeded,
|
||||||
BOOL unicode);
|
BOOL unicode);
|
||||||
|
|
||||||
|
/* RtlCreateUnicodeStringFromAsciiz will return an empty string in the buffer
|
||||||
|
if passed a NULL string. This returns NULLs to the result.
|
||||||
|
*/
|
||||||
|
static inline PWSTR asciitounicode( UNICODE_STRING * usBufferPtr, LPCSTR src )
|
||||||
|
{
|
||||||
|
if ( (src) )
|
||||||
|
{
|
||||||
|
RtlCreateUnicodeStringFromAsciiz(usBufferPtr, src);
|
||||||
|
return usBufferPtr->Buffer;
|
||||||
|
}
|
||||||
|
usBufferPtr->Buffer = NULL; /* so that RtlFreeUnicodeString won't barf */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
WINSPOOL_SetDefaultPrinter(const char *devname, const char *name,BOOL force) {
|
WINSPOOL_SetDefaultPrinter(const char *devname, const char *name,BOOL force) {
|
||||||
char qbuf[200];
|
char qbuf[200];
|
||||||
|
@ -157,9 +172,30 @@ CUPS_LoadPrinters(void) {
|
||||||
|
|
||||||
nrofdests = pcupsGetPrinters(&printers);
|
nrofdests = pcupsGetPrinters(&printers);
|
||||||
for (i=0;i<nrofdests;i++) {
|
for (i=0;i<nrofdests;i++) {
|
||||||
const char *ppd = pcupsGetPPD(printers[i]);
|
const char *ppd;
|
||||||
char *port,*devline;
|
char *port,*devline;
|
||||||
|
WCHAR *pNameW;
|
||||||
|
HKEY hkeyPrinters, hkeyPrinter;
|
||||||
|
|
||||||
|
/* First check that the printer doesn't exist already */
|
||||||
|
pNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, printers[i]);
|
||||||
|
if (RegCreateKeyA(HKEY_LOCAL_MACHINE, Printers, &hkeyPrinters) ==
|
||||||
|
ERROR_SUCCESS) {
|
||||||
|
if (RegOpenKeyW(hkeyPrinters, pNameW, &hkeyPrinter) ==
|
||||||
|
ERROR_SUCCESS) {
|
||||||
|
/* We know this printer already */
|
||||||
|
RegCloseKey(hkeyPrinter);
|
||||||
|
RegCloseKey(hkeyPrinters);
|
||||||
|
HeapFree(GetProcessHeap(),0,pNameW);
|
||||||
|
TRACE("Printer %s already known. Skipping detection\n", printers[i]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
RegCloseKey(hkeyPrinters);
|
||||||
|
}
|
||||||
|
HeapFree(GetProcessHeap(),0,pNameW);
|
||||||
|
|
||||||
|
/* OK, we haven't seen this one yet. Request PPD for it */
|
||||||
|
ppd = pcupsGetPPD(printers[i]);
|
||||||
if (!ppd) {
|
if (!ppd) {
|
||||||
WARN("No ppd file for %s.\n",printers[i]);
|
WARN("No ppd file for %s.\n",printers[i]);
|
||||||
/* If this was going to be the default printer,
|
/* If this was going to be the default printer,
|
||||||
|
@ -554,29 +590,18 @@ static LPPRINTER_INFO_2W PRINTER_INFO_2AtoW(HANDLE heap, LPPRINTER_INFO_2A piA)
|
||||||
piW = HeapAlloc(heap, 0, sizeof(*piW));
|
piW = HeapAlloc(heap, 0, sizeof(*piW));
|
||||||
memcpy(piW, piA, sizeof(*piW)); /* copy everything first */
|
memcpy(piW, piA, sizeof(*piW)); /* copy everything first */
|
||||||
|
|
||||||
RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pServerName);
|
piW->pServerName = asciitounicode(&usBuffer,piA->pServerName);
|
||||||
piW->pServerName = usBuffer.Buffer;
|
piW->pPrinterName = asciitounicode(&usBuffer,piA->pPrinterName);
|
||||||
RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pPrinterName);
|
piW->pShareName = asciitounicode(&usBuffer,piA->pShareName);
|
||||||
piW->pPrinterName = usBuffer.Buffer;
|
piW->pPortName = asciitounicode(&usBuffer,piA->pPortName);
|
||||||
RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pShareName);
|
piW->pDriverName = asciitounicode(&usBuffer,piA->pDriverName);
|
||||||
piW->pShareName = usBuffer.Buffer;
|
piW->pComment = asciitounicode(&usBuffer,piA->pComment);
|
||||||
RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pPortName);
|
piW->pLocation = asciitounicode(&usBuffer,piA->pLocation);
|
||||||
piW->pPortName = usBuffer.Buffer;
|
|
||||||
RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pDriverName);
|
|
||||||
piW->pDriverName = usBuffer.Buffer;
|
|
||||||
RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pComment);
|
|
||||||
piW->pComment = usBuffer.Buffer;
|
|
||||||
RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pLocation);
|
|
||||||
piW->pLocation = usBuffer.Buffer;
|
|
||||||
piW->pDevMode = DEVMODEdupAtoW(heap, piA->pDevMode);
|
piW->pDevMode = DEVMODEdupAtoW(heap, piA->pDevMode);
|
||||||
RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pSepFile);
|
piW->pSepFile = asciitounicode(&usBuffer,piA->pSepFile);
|
||||||
piW->pSepFile = usBuffer.Buffer;
|
piW->pPrintProcessor = asciitounicode(&usBuffer,piA->pPrintProcessor);
|
||||||
RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pPrintProcessor);
|
piW->pDatatype = asciitounicode(&usBuffer,piA->pDatatype);
|
||||||
piW->pPrintProcessor = usBuffer.Buffer;
|
piW->pParameters = asciitounicode(&usBuffer,piA->pParameters);
|
||||||
RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pDatatype);
|
|
||||||
piW->pDatatype = usBuffer.Buffer;
|
|
||||||
RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pParameters);
|
|
||||||
piW->pParameters = usBuffer.Buffer;
|
|
||||||
return piW;
|
return piW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -777,19 +802,19 @@ BOOL WINAPI OpenPrinterA(LPSTR lpPrinterName,HANDLE *phPrinter,
|
||||||
UNICODE_STRING lpPrinterNameW;
|
UNICODE_STRING lpPrinterNameW;
|
||||||
UNICODE_STRING usBuffer;
|
UNICODE_STRING usBuffer;
|
||||||
PRINTER_DEFAULTSW DefaultW, *pDefaultW = NULL;
|
PRINTER_DEFAULTSW DefaultW, *pDefaultW = NULL;
|
||||||
|
PWSTR pwstrPrinterNameW;
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
||||||
RtlCreateUnicodeStringFromAsciiz(&lpPrinterNameW,lpPrinterName);
|
pwstrPrinterNameW = asciitounicode(&lpPrinterNameW,lpPrinterName);
|
||||||
|
|
||||||
if(pDefault) {
|
if(pDefault) {
|
||||||
RtlCreateUnicodeStringFromAsciiz(&usBuffer,pDefault->pDatatype);
|
DefaultW.pDatatype = asciitounicode(&usBuffer,pDefault->pDatatype);
|
||||||
DefaultW.pDatatype = usBuffer.Buffer;
|
|
||||||
DefaultW.pDevMode = DEVMODEdupAtoW(GetProcessHeap(),
|
DefaultW.pDevMode = DEVMODEdupAtoW(GetProcessHeap(),
|
||||||
pDefault->pDevMode);
|
pDefault->pDevMode);
|
||||||
DefaultW.DesiredAccess = pDefault->DesiredAccess;
|
DefaultW.DesiredAccess = pDefault->DesiredAccess;
|
||||||
pDefaultW = &DefaultW;
|
pDefaultW = &DefaultW;
|
||||||
}
|
}
|
||||||
ret = OpenPrinterW(lpPrinterNameW.Buffer, phPrinter, pDefaultW);
|
ret = OpenPrinterW(pwstrPrinterNameW, phPrinter, pDefaultW);
|
||||||
if(pDefault) {
|
if(pDefault) {
|
||||||
RtlFreeUnicodeString(&usBuffer);
|
RtlFreeUnicodeString(&usBuffer);
|
||||||
HeapFree(GetProcessHeap(), 0, DefaultW.pDevMode);
|
HeapFree(GetProcessHeap(), 0, DefaultW.pDevMode);
|
||||||
|
@ -1183,6 +1208,7 @@ HANDLE WINAPI AddPrinterW(LPWSTR pName, DWORD Level, LPBYTE pPrinter)
|
||||||
HANDLE WINAPI AddPrinterA(LPSTR pName, DWORD Level, LPBYTE pPrinter)
|
HANDLE WINAPI AddPrinterA(LPSTR pName, DWORD Level, LPBYTE pPrinter)
|
||||||
{
|
{
|
||||||
UNICODE_STRING pNameW;
|
UNICODE_STRING pNameW;
|
||||||
|
PWSTR pwstrNameW;
|
||||||
PRINTER_INFO_2W *piW;
|
PRINTER_INFO_2W *piW;
|
||||||
PRINTER_INFO_2A *piA = (PRINTER_INFO_2A*)pPrinter;
|
PRINTER_INFO_2A *piA = (PRINTER_INFO_2A*)pPrinter;
|
||||||
HANDLE ret;
|
HANDLE ret;
|
||||||
|
@ -1193,10 +1219,10 @@ HANDLE WINAPI AddPrinterA(LPSTR pName, DWORD Level, LPBYTE pPrinter)
|
||||||
SetLastError(ERROR_INVALID_LEVEL);
|
SetLastError(ERROR_INVALID_LEVEL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
RtlCreateUnicodeStringFromAsciiz(&pNameW,pName);
|
pwstrNameW = asciitounicode(&pNameW,pName);
|
||||||
piW = PRINTER_INFO_2AtoW(GetProcessHeap(), piA);
|
piW = PRINTER_INFO_2AtoW(GetProcessHeap(), piA);
|
||||||
|
|
||||||
ret = AddPrinterW(pNameW.Buffer, Level, (LPBYTE)piW);
|
ret = AddPrinterW(pwstrNameW, Level, (LPBYTE)piW);
|
||||||
|
|
||||||
FREE_PRINTER_INFO_2W(GetProcessHeap(), piW);
|
FREE_PRINTER_INFO_2W(GetProcessHeap(), piW);
|
||||||
RtlFreeUnicodeString(&pNameW);
|
RtlFreeUnicodeString(&pNameW);
|
||||||
|
@ -2166,8 +2192,11 @@ BOOL WINAPI EnumPrintersA(DWORD dwType, LPSTR lpszName,
|
||||||
{
|
{
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
UNICODE_STRING lpszNameW;
|
UNICODE_STRING lpszNameW;
|
||||||
|
PWSTR pwstrNameW;
|
||||||
|
|
||||||
RtlCreateUnicodeStringFromAsciiz(&lpszNameW,lpszName);
|
RtlCreateUnicodeStringFromAsciiz(&lpszNameW,lpszName);
|
||||||
ret = WINSPOOL_EnumPrinters(dwType, lpszNameW.Buffer, dwLevel, lpbPrinters, cbBuf,
|
pwstrNameW = asciitounicode(&lpszNameW,lpszName);
|
||||||
|
ret = WINSPOOL_EnumPrinters(dwType, pwstrNameW, dwLevel, lpbPrinters, cbBuf,
|
||||||
lpdwNeeded, lpdwReturned, FALSE);
|
lpdwNeeded, lpdwReturned, FALSE);
|
||||||
RtlFreeUnicodeString(&lpszNameW);
|
RtlFreeUnicodeString(&lpszNameW);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -2440,8 +2469,10 @@ BOOL WINAPI GetPrinterDriverA(HANDLE hPrinter, LPSTR pEnvironment,
|
||||||
{
|
{
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
UNICODE_STRING pEnvW;
|
UNICODE_STRING pEnvW;
|
||||||
RtlCreateUnicodeStringFromAsciiz(&pEnvW, pEnvironment);
|
PWSTR pwstrEnvW;
|
||||||
ret = WINSPOOL_GetPrinterDriver(hPrinter, pEnvW.Buffer, Level, pDriverInfo,
|
|
||||||
|
pwstrEnvW = asciitounicode(&pEnvW, pEnvironment);
|
||||||
|
ret = WINSPOOL_GetPrinterDriver(hPrinter, pwstrEnvW, Level, pDriverInfo,
|
||||||
cbBuf, pcbNeeded, FALSE);
|
cbBuf, pcbNeeded, FALSE);
|
||||||
RtlFreeUnicodeString(&pEnvW);
|
RtlFreeUnicodeString(&pEnvW);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -2816,19 +2847,16 @@ BOOL WINAPI EnumPrinterDriversA(LPSTR pName, LPSTR pEnvironment, DWORD Level,
|
||||||
LPDWORD pcbNeeded, LPDWORD pcReturned)
|
LPDWORD pcbNeeded, LPDWORD pcReturned)
|
||||||
{ BOOL ret;
|
{ BOOL ret;
|
||||||
UNICODE_STRING pNameW, pEnvironmentW;
|
UNICODE_STRING pNameW, pEnvironmentW;
|
||||||
|
PWSTR pwstrNameW, pwstrEnvironmentW;
|
||||||
|
|
||||||
if(pName)
|
pwstrNameW = asciitounicode(&pNameW, pName);
|
||||||
RtlCreateUnicodeStringFromAsciiz(&pNameW, pName);
|
pwstrEnvironmentW = asciitounicode(&pEnvironmentW, pEnvironment);
|
||||||
if(pEnvironment)
|
|
||||||
RtlCreateUnicodeStringFromAsciiz(&pEnvironmentW, pEnvironment);
|
|
||||||
|
|
||||||
ret = WINSPOOL_EnumPrinterDrivers(pNameW.Buffer, pEnvironmentW.Buffer,
|
ret = WINSPOOL_EnumPrinterDrivers(pwstrNameW, pwstrEnvironmentW,
|
||||||
Level, pDriverInfo, cbBuf, pcbNeeded,
|
Level, pDriverInfo, cbBuf, pcbNeeded,
|
||||||
pcReturned, FALSE);
|
pcReturned, FALSE);
|
||||||
if(pName)
|
RtlFreeUnicodeString(&pNameW);
|
||||||
RtlFreeUnicodeString(&pNameW);
|
RtlFreeUnicodeString(&pEnvironmentW);
|
||||||
if(pEnvironment)
|
|
||||||
RtlFreeUnicodeString(&pEnvironmentW);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue