[PATCH] winspool: Use the Backend for EnumPrinters

Detlef Riekenberg wine.dev at web.de
Sun Apr 13 15:55:30 CDT 2008


---
 dlls/winspool.drv/info.c |  300 +++++-----------------------------------------
 1 files changed, 33 insertions(+), 267 deletions(-)

diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c
index dadc61f..4e0ab0c 100644
--- a/dlls/winspool.drv/info.c
+++ b/dlls/winspool.drv/info.c
@@ -3933,63 +3933,6 @@ static BOOL WINSPOOL_GetDevModeFromReg(HKEY hkey, LPCWSTR ValueName,
 }
 
 /*********************************************************************
- *    WINSPOOL_GetPrinter_1
- *
- * Fills out a PRINTER_INFO_1A|W struct storing the strings in buf.
- * The strings are either stored as unicode or ascii.
- */
-static BOOL WINSPOOL_GetPrinter_1(HKEY hkeyPrinter, PRINTER_INFO_1W *pi1,
-				  LPBYTE buf, DWORD cbBuf, LPDWORD pcbNeeded,
-				  BOOL unicode)
-{
-    DWORD size, left = cbBuf;
-    BOOL space = (cbBuf > 0);
-    LPBYTE ptr = buf;
-
-    *pcbNeeded = 0;
-
-    if(WINSPOOL_GetStringFromReg(hkeyPrinter, NameW, ptr, left, &size,
-				 unicode)) {
-        if(space && size <= left) {
-	    pi1->pName = (LPWSTR)ptr;
-	    ptr += size;
-	    left -= size;
-	} else
-	    space = FALSE;
-	*pcbNeeded += size;
-    }
-
-    /* FIXME: pDescription should be something like "Name,Driver_Name,". */
-    if(WINSPOOL_GetStringFromReg(hkeyPrinter, NameW, ptr, left, &size,
-				 unicode)) {
-        if(space && size <= left) {
-	    pi1->pDescription = (LPWSTR)ptr;
-	    ptr += size;
-	    left -= size;
-	} else
-	    space = FALSE;
-	*pcbNeeded += size;
-    }
-
-    if(WINSPOOL_GetStringFromReg(hkeyPrinter, DescriptionW, ptr, left, &size,
-				 unicode)) {
-        if(space && size <= left) {
-	    pi1->pComment = (LPWSTR)ptr;
-	    ptr += size;
-	    left -= size;
-	} else
-	    space = FALSE;
-	*pcbNeeded += size;
-    }
-
-    if(pi1) pi1->Flags = PRINTER_ENUM_ICON8; /* We're a printer */
-
-    if(!space && pi1) /* zero out pi1 if we can't completely fill buf */
-        memset(pi1, 0, sizeof(*pi1));
-
-    return space;
-}
-/*********************************************************************
  *    WINSPOOL_GetPrinter_2
  *
  * Fills out a PRINTER_INFO_2A|W struct storing the strings in buf.
@@ -4489,223 +4432,46 @@ BOOL WINAPI GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter,
 			       FALSE);
 }
 
-/*****************************************************************************
- *          WINSPOOL_EnumPrinters
- *
- *    Implementation of EnumPrintersA|W
- */
-static BOOL WINSPOOL_EnumPrinters(DWORD dwType, LPWSTR lpszName,
-				  DWORD dwLevel, LPBYTE lpbPrinters,
-				  DWORD cbBuf, LPDWORD lpdwNeeded,
-				  LPDWORD lpdwReturned, BOOL unicode)
-
-{
-    HKEY hkeyPrinters, hkeyPrinter;
-    WCHAR PrinterName[255];
-    DWORD needed = 0, number = 0;
-    DWORD used, i, left;
-    PBYTE pi, buf;
-
-    if(lpbPrinters)
-        memset(lpbPrinters, 0, cbBuf);
-    if(lpdwReturned)
-        *lpdwReturned = 0;
-    if(lpdwNeeded)
-        *lpdwNeeded = 0;
-
-    /* PRINTER_ENUM_DEFAULT is only supported under win9x, we behave like NT */
-    if(dwType == PRINTER_ENUM_DEFAULT)
-	return TRUE;
-
-    if (dwType & PRINTER_ENUM_CONNECTIONS) {
-        TRACE("ignoring PRINTER_ENUM_CONNECTIONS\n");
-        dwType &= ~PRINTER_ENUM_CONNECTIONS; /* we don't handle that */
-        if (!dwType) {
-            FIXME("We don't handle PRINTER_ENUM_CONNECTIONS\n");
-            *lpdwNeeded = 0;
-            *lpdwReturned = 0;
-            return TRUE;
-        }
-
-    }
-
-    if (!((dwType & PRINTER_ENUM_LOCAL) || (dwType & PRINTER_ENUM_NAME))) {
-        FIXME("dwType = %08x\n", dwType);
-	SetLastError(ERROR_INVALID_FLAGS);
-	return FALSE;
-    }
-
-    if(RegCreateKeyW(HKEY_LOCAL_MACHINE, PrintersW, &hkeyPrinters) !=
-       ERROR_SUCCESS) {
-        ERR("Can't create Printers key\n");
-	return FALSE;
-    }
-
-    if(RegQueryInfoKeyA(hkeyPrinters, NULL, NULL, NULL, &number, NULL, NULL,
-			NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) {
-        RegCloseKey(hkeyPrinters);
-	ERR("Can't query Printers key\n");
-	return FALSE;
-    }
-    TRACE("Found %d printers\n", number);
+/******************************************************************
+ * EnumPrintersW [WINSPOOL.@]
+ *
+ *  Enumerates the available printers, print servers and print providers,
+ *  depending on flags, pName and level.
+ *
+ * PARAMS
+ *  flags      [I] select Types of Objects to enumerate
+ *  pName      [I] Name of Objects to enumerate 
+ *  level      [I] level of the requested PRINTER_INFO structure
+ *  pPrinters  [O] PTR to Buffer that receives the Result
+ *  cbBuf      [I] Size of Buffer at pPrinters
+ *  pcbNeeded  [O] PTR to DWORD that receives the size in Bytes used / required for pPrinters
+ *  pcReturned [O] PTR to DWORD that receives the number of objects in pPrinters
+ *
+ * RETURNS
+ *  Failure: FALSE
+ *  Success: TRUE
+ *
+ */
+BOOL WINAPI EnumPrintersW(DWORD flags, LPWSTR pName, DWORD level, LPBYTE pPrinters,
+                          DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)
+{
+    TRACE("(0x%x, %s, %u, %p, %d, %p, %p)\n", flags, debugstr_w(pName), level,
+                pPrinters, cbBuf, pcbNeeded, pcReturned);
 
-    switch(dwLevel) {
-    case 1:
-        used = number * sizeof(PRINTER_INFO_1W);
-        break;
-    case 2:
-        used = number * sizeof(PRINTER_INFO_2W);
-	break;
-    case 4:
-        used = number * sizeof(PRINTER_INFO_4W);
-	break;
-    case 5:
-        used = number * sizeof(PRINTER_INFO_5W);
-	break;
+    if ((backend == NULL)  && !load_backend()) return FALSE;
 
-    default:
+    if ((level == 0) || (level == 3) || (level > 5)) {
         SetLastError(ERROR_INVALID_LEVEL);
-	RegCloseKey(hkeyPrinters);
-	return FALSE;
-    }
-    pi = (used <= cbBuf) ? lpbPrinters : NULL;
-
-    for(i = 0; i < number; i++) {
-        if(RegEnumKeyW(hkeyPrinters, i, PrinterName, sizeof(PrinterName)/sizeof(PrinterName[0])) !=
-	   ERROR_SUCCESS) {
-	    ERR("Can't enum key number %d\n", i);
-	    RegCloseKey(hkeyPrinters);
-	    return FALSE;
-	}
-	TRACE("Printer %d is %s\n", i, debugstr_w(PrinterName));
-	if(RegOpenKeyW(hkeyPrinters, PrinterName, &hkeyPrinter) !=
-	   ERROR_SUCCESS) {
-	    ERR("Can't open key %s\n", debugstr_w(PrinterName));
-	    RegCloseKey(hkeyPrinters);
-	    return FALSE;
-	}
-
-	if(cbBuf > used) {
-	    buf = lpbPrinters + used;
-	    left = cbBuf - used;
-	} else {
-	    buf = NULL;
-	    left = 0;
-	}
-
-	switch(dwLevel) {
-	case 1:
-	    WINSPOOL_GetPrinter_1(hkeyPrinter, (PRINTER_INFO_1W *)pi, buf,
-				  left, &needed, unicode);
-	    used += needed;
-	    if(pi) pi += sizeof(PRINTER_INFO_1W);
-	    break;
-	case 2:
-	    WINSPOOL_GetPrinter_2(hkeyPrinter, (PRINTER_INFO_2W *)pi, buf,
-				  left, &needed, unicode);
-	    used += needed;
-	    if(pi) pi += sizeof(PRINTER_INFO_2W);
-	    break;
-	case 4:
-	    WINSPOOL_GetPrinter_4(hkeyPrinter, (PRINTER_INFO_4W *)pi, buf,
-				  left, &needed, unicode);
-	    used += needed;
-	    if(pi) pi += sizeof(PRINTER_INFO_4W);
-	    break;
-	case 5:
-	    WINSPOOL_GetPrinter_5(hkeyPrinter, (PRINTER_INFO_5W *)pi, buf,
-				  left, &needed, unicode);
-	    used += needed;
-	    if(pi) pi += sizeof(PRINTER_INFO_5W);
-	    break;
-	default:
-	    ERR("Shouldn't be here!\n");
-	    RegCloseKey(hkeyPrinter);
-	    RegCloseKey(hkeyPrinters);
-	    return FALSE;
-	}
-	RegCloseKey(hkeyPrinter);
+        return FALSE;
     }
-    RegCloseKey(hkeyPrinters);
-
-    if(lpdwNeeded)
-        *lpdwNeeded = used;
 
-    if(used > cbBuf) {
-        if(lpbPrinters)
-	    memset(lpbPrinters, 0, cbBuf);
-	SetLastError(ERROR_INSUFFICIENT_BUFFER);
-	return FALSE;
+    if (pcbNeeded == NULL) {
+        /* (pcbNeeded == NULL) is ignored in win9x */
+        SetLastError(RPC_X_NULL_REF_POINTER);
+        return FALSE;
     }
-    if(lpdwReturned)
-        *lpdwReturned = number;
-    SetLastError(ERROR_SUCCESS);
-    return TRUE;
-}
-
 
-/******************************************************************
- *              EnumPrintersW        [WINSPOOL.@]
- *
- *    Enumerates the available printers, print servers and print
- *    providers, depending on the specified flags, name and level.
- *
- * RETURNS:
- *
- *    If level is set to 1:
- *      Returns an array of PRINTER_INFO_1 data structures in the
- *      lpbPrinters buffer.
- *
- *    If level is set to 2:
- *		Possible flags: PRINTER_ENUM_CONNECTIONS, PRINTER_ENUM_LOCAL.
- *      Returns an array of PRINTER_INFO_2 data structures in the
- *      lpbPrinters buffer. Note that according to MSDN also an
- *      OpenPrinter should be performed on every remote printer.
- *
- *    If level is set to 4 (officially WinNT only):
- *		Possible flags: PRINTER_ENUM_CONNECTIONS, PRINTER_ENUM_LOCAL.
- *      Fast: Only the registry is queried to retrieve printer names,
- *      no connection to the driver is made.
- *      Returns an array of PRINTER_INFO_4 data structures in the
- *      lpbPrinters buffer.
- *
- *    If level is set to 5 (officially WinNT4/Win9x only):
- *      Fast: Only the registry is queried to retrieve printer names,
- *      no connection to the driver is made.
- *      Returns an array of PRINTER_INFO_5 data structures in the
- *      lpbPrinters buffer.
- *
- *    If level set to 3 or 6+:
- *	    returns zero (failure!)
- *
- *    Returns nonzero (TRUE) on success, or zero on failure, use GetLastError
- *    for information.
- *
- * BUGS:
- *    - Only PRINTER_ENUM_LOCAL and PRINTER_ENUM_NAME are implemented.
- *    - Only levels 2, 4 and 5 are implemented at the moment.
- *    - 16-bit printer drivers are not enumerated.
- *    - Returned amount of bytes used/needed does not match the real Windoze
- *      implementation (as in this implementation, all strings are part
- *      of the buffer, whereas Win32 keeps them somewhere else)
- *    - At level 2, EnumPrinters should also call OpenPrinter for remote printers.
- *
- * NOTE:
- *    - In a regular Wine installation, no registry settings for printers
- *      exist, which makes this function return an empty list.
- */
-BOOL  WINAPI EnumPrintersW(
-		DWORD dwType,        /* [in] Types of print objects to enumerate */
-                LPWSTR lpszName,     /* [in] name of objects to enumerate */
-	        DWORD dwLevel,       /* [in] type of printer info structure */
-                LPBYTE lpbPrinters,  /* [out] buffer which receives info */
-		DWORD cbBuf,         /* [in] max size of buffer in bytes */
-		LPDWORD lpdwNeeded,  /* [out] pointer to var: # bytes used/needed */
-		LPDWORD lpdwReturned /* [out] number of entries returned */
-		)
-{
-    return WINSPOOL_EnumPrinters(dwType, lpszName, dwLevel, lpbPrinters, cbBuf,
-				 lpdwNeeded, lpdwReturned, TRUE);
+    return backend->fpEnumPrinters(flags, pName, level, pPrinters, cbBuf, pcbNeeded, pcReturned);
 }
 
 /******************************************************************
-- 
1.5.3.6


--=-MpDad12rNGyaqSNGvGZ4--




More information about the wine-patches mailing list