2 * Implementation of the Spooler-Service helper DLL
4 * Copyright 2006 Detlef Riekenberg
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "ddk/winsplp.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(spoolss);
36 /* ################################ */
38 static CRITICAL_SECTION backend_cs;
39 static CRITICAL_SECTION_DEBUG backend_cs_debug =
42 { &backend_cs_debug.ProcessLocksList, &backend_cs_debug.ProcessLocksList },
43 0, 0, { (DWORD_PTR)(__FILE__ ": backend_cs") }
45 static CRITICAL_SECTION backend_cs = { &backend_cs_debug, -1, 0, 0, 0, 0 };
47 /* ################################ */
49 static HMODULE hwinspool;
50 static HMODULE hlocalspl;
51 static BOOL (WINAPI *pInitializePrintProvidor)(LPPRINTPROVIDOR, DWORD, LPWSTR);
53 static PRINTPROVIDOR * backend;
55 /* ################################ */
57 static const WCHAR localspldllW[] = {'l','o','c','a','l','s','p','l','.','d','l','l',0};
58 static const WCHAR winspooldrvW[] = {'w','i','n','s','p','o','o','l','.','d','r','v',0};
60 /******************************************************************************
61 * backend_load [internal]
63 * load and init our backend (the local printprovider: "localspl.dll")
69 * Failure: FALSE and RPC_S_SERVER_UNAVAILABLE
72 * In windows, the spooler router (spoolss.dll) support multiple
73 * printprovider (localspl.dll for the local system)
76 static BOOL backend_load(void)
78 static PRINTPROVIDOR mybackend;
81 if (backend) return TRUE;
83 EnterCriticalSection(&backend_cs);
84 hlocalspl = LoadLibraryW(localspldllW);
86 pInitializePrintProvidor = (void *) GetProcAddress(hlocalspl, "InitializePrintProvidor");
87 if (pInitializePrintProvidor) {
89 /* native localspl does not clear unused entries */
90 memset(&mybackend, 0, sizeof(mybackend));
91 res = pInitializePrintProvidor(&mybackend, sizeof(mybackend), NULL);
94 LeaveCriticalSection(&backend_cs);
95 TRACE("backend: %p (%p)\n", backend, hlocalspl);
99 FreeLibrary(hlocalspl);
102 LeaveCriticalSection(&backend_cs);
104 WARN("failed to load the backend: %u\n", GetLastError());
105 SetLastError(RPC_S_SERVER_UNAVAILABLE);
109 /******************************************************************
110 * unload_backend [internal]
113 static void backend_unload(void)
115 EnterCriticalSection(&backend_cs);
118 FreeLibrary(hlocalspl);
120 LeaveCriticalSection(&backend_cs);
123 /******************************************************************************
126 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
128 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
131 case DLL_WINE_PREATTACH:
132 return FALSE; /* prefer native version */
133 case DLL_PROCESS_ATTACH: {
134 DisableThreadLibraryCalls(hinstDLL);
137 case DLL_PROCESS_DETACH:
145 /******************************************************************
146 * AllocSplStr [SPOOLSS.@]
148 * Create a copy from the String on the Spooler-Heap
151 * pwstr [I] PTR to the String to copy
155 * Success: PTR to the copied String
158 LPWSTR WINAPI AllocSplStr(LPCWSTR pwstr)
163 TRACE("(%s)\n", debugstr_w(pwstr));
164 if (!pwstr) return NULL;
166 len = (lstrlenW(pwstr) + 1) * sizeof(WCHAR);
167 res = HeapAlloc(GetProcessHeap(), 0, len);
168 if (res) lstrcpyW(res, pwstr);
170 TRACE("returning %p\n", res);
174 /******************************************************************
175 * BuildOtherNamesFromMachineName [SPOOLSS.@]
177 BOOL WINAPI BuildOtherNamesFromMachineName(LPVOID * ptr1, LPVOID * ptr2)
179 FIXME("(%p, %p) stub\n", ptr1, ptr2);
186 /******************************************************************
187 * DllAllocSplMem [SPOOLSS.@]
189 * Allocate cleared memory from the spooler heap
192 * size [I] Number of bytes to allocate
196 * Success: PTR to the allocated memory
199 * We use the process heap (Windows use a separate spooler heap)
202 LPVOID WINAPI DllAllocSplMem(DWORD size)
206 res = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
207 TRACE("(%d) => %p\n", size, res);
211 /******************************************************************
212 * DllFreeSplMem [SPOOLSS.@]
214 * Free the allocated spooler memory
217 * memory [I] PTR to the memory allocated by DllAllocSplMem
224 * We use the process heap (Windows use a separate spooler heap)
228 BOOL WINAPI DllFreeSplMem(LPBYTE memory)
230 TRACE("(%p)\n", memory);
231 return HeapFree(GetProcessHeap(), 0, memory);
234 /******************************************************************
235 * DllFreeSplStr [SPOOLSS.@]
237 * Free the allocated Spooler-String
240 * pwstr [I] PTR to the WSTR, allocated by AllocSplStr
248 BOOL WINAPI DllFreeSplStr(LPWSTR pwstr)
250 TRACE("(%s) PTR: %p\n", debugstr_w(pwstr), pwstr);
251 return HeapFree(GetProcessHeap(), 0, pwstr);
255 /******************************************************************
256 * ImpersonatePrinterClient [SPOOLSS.@]
258 BOOL WINAPI ImpersonatePrinterClient(HANDLE hToken)
260 FIXME("(%p) stub\n", hToken);
264 /******************************************************************
265 * InitializeRouter [SPOOLSS.@]
267 BOOL WINAPI InitializeRouter(void)
270 return backend_load();
273 /******************************************************************
274 * IsLocalCall [SPOOLSS.@]
276 BOOL WINAPI IsLocalCall(void)
282 /******************************************************************
283 * RevertToPrinterSelf [SPOOLSS.@]
285 HANDLE WINAPI RevertToPrinterSelf(void)
288 return (HANDLE) 0xdead0947;
291 /******************************************************************
292 * SplInitializeWinSpoolDrv [SPOOLSS.@]
294 * Dynamic load "winspool.drv" and fill an array with some function-pointer
297 * table [I] array of function-pointer to fill
304 * Native "spoolss.dll" from w2k fill the table with 11 Function-Pointer.
305 * We implement the XP-Version (The table has only 9 Pointer)
308 BOOL WINAPI SplInitializeWinSpoolDrv(LPVOID * table)
312 TRACE("(%p)\n", table);
314 hwinspool = LoadLibraryW(winspooldrvW);
315 if (!hwinspool) return FALSE;
317 table[0] = (void *) GetProcAddress(hwinspool, "OpenPrinterW");
318 table[1] = (void *) GetProcAddress(hwinspool, "ClosePrinter");
319 table[2] = (void *) GetProcAddress(hwinspool, "SpoolerDevQueryPrintW");
320 table[3] = (void *) GetProcAddress(hwinspool, "SpoolerPrinterEvent");
321 table[4] = (void *) GetProcAddress(hwinspool, "DocumentPropertiesW");
322 table[5] = (void *) GetProcAddress(hwinspool, (LPSTR) 212); /* LoadPrinterDriver */
323 table[6] = (void *) GetProcAddress(hwinspool, (LPSTR) 213); /* RefCntLoadDriver */
324 table[7] = (void *) GetProcAddress(hwinspool, (LPSTR) 214); /* RefCntUnloadDriver */
325 table[8] = (void *) GetProcAddress(hwinspool, (LPSTR) 215); /* ForceUnloadDriver */
327 for (res = 0; res < 9; res++) {
328 if (table[res] == NULL) return FALSE;
335 /******************************************************************
336 * SplIsUpgrade [SPOOLSS.@]
338 BOOL WINAPI SplIsUpgrade(void)
344 /******************************************************************
345 * SpoolerHasInitialized [SPOOLSS.@]
347 BOOL WINAPI SpoolerHasInitialized(void)
353 /******************************************************************
354 * SpoolerInit [SPOOLSS.@]
356 BOOL WINAPI SpoolerInit(void)
362 /******************************************************************
363 * WaitForSpoolerInitialization [SPOOLSS.@]
365 BOOL WINAPI WaitForSpoolerInitialization(void)