1 /*
2 * Implementation of the Spooler-Service helper DLL
3 *
4 * Copyright 2006 Detlef Riekenberg
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "winreg.h"
27
28 #include "wingdi.h"
29 #include "winspool.h"
30 #include "ddk/winsplp.h"
31
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(spoolss);
35
36 /* ################################ */
37
38 static CRITICAL_SECTION backend_cs;
39 static CRITICAL_SECTION_DEBUG backend_cs_debug =
40 {
41 0, 0, &backend_cs,
42 { &backend_cs_debug.ProcessLocksList, &backend_cs_debug.ProcessLocksList },
43 0, 0, { (DWORD_PTR)(__FILE__ ": backend_cs") }
44 };
45 static CRITICAL_SECTION backend_cs = { &backend_cs_debug, -1, 0, 0, 0, 0 };
46
47 /* ################################ */
48
49 static HMODULE hwinspool;
50 static HMODULE hlocalspl;
51 static BOOL (WINAPI *pInitializePrintProvidor)(LPPRINTPROVIDOR, DWORD, LPWSTR);
52
53 static PRINTPROVIDOR * backend;
54
55 /* ################################ */
56
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};
59
60 /******************************************************************************
61 * backend_load [internal]
62 *
63 * load and init our backend (the local printprovider: "localspl.dll")
64 *
65 * PARAMS
66 *
67 * RETURNS
68 * Success: TRUE
69 * Failure: FALSE and RPC_S_SERVER_UNAVAILABLE
70 *
71 * NOTES
72 * In windows, the spooler router (spoolss.dll) support multiple
73 * printprovider (localspl.dll for the local system)
74 *
75 */
76 static BOOL backend_load(void)
77 {
78 static PRINTPROVIDOR mybackend;
79 DWORD res;
80
81 if (backend) return TRUE;
82
83 EnterCriticalSection(&backend_cs);
84 hlocalspl = LoadLibraryW(localspldllW);
85 if (hlocalspl) {
86 pInitializePrintProvidor = (void *) GetProcAddress(hlocalspl, "InitializePrintProvidor");
87 if (pInitializePrintProvidor) {
88
89 /* native localspl does not clear unused entries */
90 memset(&mybackend, 0, sizeof(mybackend));
91 res = pInitializePrintProvidor(&mybackend, sizeof(mybackend), NULL);
92 if (res) {
93 backend = &mybackend;
94 LeaveCriticalSection(&backend_cs);
95 TRACE("backend: %p (%p)\n", backend, hlocalspl);
96 return TRUE;
97 }
98 }
99 FreeLibrary(hlocalspl);
100 }
101
102 LeaveCriticalSection(&backend_cs);
103
104 WARN("failed to load the backend: %u\n", GetLastError());
105 SetLastError(RPC_S_SERVER_UNAVAILABLE);
106 return FALSE;
107 }
108
109 /******************************************************************
110 * unload_backend [internal]
111 *
112 */
113 static void backend_unload(void)
114 {
115 EnterCriticalSection(&backend_cs);
116 if (backend) {
117 backend = NULL;
118 FreeLibrary(hlocalspl);
119 }
120 LeaveCriticalSection(&backend_cs);
121 }
122
123 /******************************************************************************
124 *
125 */
126 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
127 {
128 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
129
130 switch (fdwReason) {
131 case DLL_WINE_PREATTACH:
132 return FALSE; /* prefer native version */
133 case DLL_PROCESS_ATTACH: {
134 DisableThreadLibraryCalls(hinstDLL);
135 break;
136
137 case DLL_PROCESS_DETACH:
138 backend_unload();
139 break;
140 }
141 }
142 return TRUE;
143 }
144
145 /******************************************************************
146 * AllocSplStr [SPOOLSS.@]
147 *
148 * Create a copy from the String on the Spooler-Heap
149 *
150 * PARAMS
151 * pwstr [I] PTR to the String to copy
152 *
153 * RETURNS
154 * Failure: NULL
155 * Success: PTR to the copied String
156 *
157 */
158 LPWSTR WINAPI AllocSplStr(LPCWSTR pwstr)
159 {
160 LPWSTR res = NULL;
161 DWORD len;
162
163 TRACE("(%s)\n", debugstr_w(pwstr));
164 if (!pwstr) return NULL;
165
166 len = (lstrlenW(pwstr) + 1) * sizeof(WCHAR);
167 res = HeapAlloc(GetProcessHeap(), 0, len);
168 if (res) lstrcpyW(res, pwstr);
169
170 TRACE("returning %p\n", res);
171 return res;
172 }
173
174 /******************************************************************
175 * BuildOtherNamesFromMachineName [SPOOLSS.@]
176 */
177 BOOL WINAPI BuildOtherNamesFromMachineName(LPVOID * ptr1, LPVOID * ptr2)
178 {
179 FIXME("(%p, %p) stub\n", ptr1, ptr2);
180
181 *ptr1 = NULL;
182 *ptr2 = NULL;
183 return FALSE;
184 }
185
186 /******************************************************************
187 * DllAllocSplMem [SPOOLSS.@]
188 *
189 * Allocate cleared memory from the spooler heap
190 *
191 * PARAMS
192 * size [I] Number of bytes to allocate
193 *
194 * RETURNS
195 * Failure: NULL
196 * Success: PTR to the allocated memory
197 *
198 * NOTES
199 * We use the process heap (Windows use a separate spooler heap)
200 *
201 */
202 LPVOID WINAPI DllAllocSplMem(DWORD size)
203 {
204 LPVOID res;
205
206 res = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
207 TRACE("(%d) => %p\n", size, res);
208 return res;
209 }
210
211 /******************************************************************
212 * DllFreeSplMem [SPOOLSS.@]
213 *
214 * Free the allocated spooler memory
215 *
216 * PARAMS
217 * memory [I] PTR to the memory allocated by DllAllocSplMem
218 *
219 * RETURNS
220 * Failure: FALSE
221 * Success: TRUE
222 *
223 * NOTES
224 * We use the process heap (Windows use a separate spooler heap)
225 *
226 */
227
228 BOOL WINAPI DllFreeSplMem(LPBYTE memory)
229 {
230 TRACE("(%p)\n", memory);
231 return HeapFree(GetProcessHeap(), 0, memory);
232 }
233
234 /******************************************************************
235 * DllFreeSplStr [SPOOLSS.@]
236 *
237 * Free the allocated Spooler-String
238 *
239 * PARAMS
240 * pwstr [I] PTR to the WSTR, allocated by AllocSplStr
241 *
242 * RETURNS
243 * Failure: FALSE
244 * Success: TRUE
245 *
246 */
247
248 BOOL WINAPI DllFreeSplStr(LPWSTR pwstr)
249 {
250 TRACE("(%s) PTR: %p\n", debugstr_w(pwstr), pwstr);
251 return HeapFree(GetProcessHeap(), 0, pwstr);
252 }
253
254
255 /******************************************************************
256 * ImpersonatePrinterClient [SPOOLSS.@]
257 */
258 BOOL WINAPI ImpersonatePrinterClient(HANDLE hToken)
259 {
260 FIXME("(%p) stub\n", hToken);
261 return TRUE;
262 }
263
264 /******************************************************************
265 * InitializeRouter [SPOOLSS.@]
266 */
267 BOOL WINAPI InitializeRouter(void)
268 {
269 TRACE("()\n");
270 return backend_load();
271 }
272
273 /******************************************************************
274 * IsLocalCall [SPOOLSS.@]
275 */
276 BOOL WINAPI IsLocalCall(void)
277 {
278 FIXME("() stub\n");
279 return TRUE;
280 }
281
282 /******************************************************************
283 * RevertToPrinterSelf [SPOOLSS.@]
284 */
285 HANDLE WINAPI RevertToPrinterSelf(void)
286 {
287 FIXME("() stub\n");
288 return (HANDLE) 0xdead0947;
289 }
290
291 /******************************************************************
292 * SplInitializeWinSpoolDrv [SPOOLSS.@]
293 *
294 * Dynamic load "winspool.drv" and fill an array with some function-pointer
295 *
296 * PARAMS
297 * table [I] array of function-pointer to fill
298 *
299 * RETURNS
300 * Success: TRUE
301 * Failure: FALSE
302 *
303 * NOTES
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)
306 *
307 */
308 BOOL WINAPI SplInitializeWinSpoolDrv(LPVOID * table)
309 {
310 DWORD res;
311
312 TRACE("(%p)\n", table);
313
314 hwinspool = LoadLibraryW(winspooldrvW);
315 if (!hwinspool) return FALSE;
316
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 */
326
327 for (res = 0; res < 9; res++) {
328 if (table[res] == NULL) return FALSE;
329 }
330
331 return TRUE;
332
333 }
334
335 /******************************************************************
336 * SplIsUpgrade [SPOOLSS.@]
337 */
338 BOOL WINAPI SplIsUpgrade(void)
339 {
340 FIXME("() stub\n");
341 return FALSE;
342 }
343
344 /******************************************************************
345 * SpoolerHasInitialized [SPOOLSS.@]
346 */
347 BOOL WINAPI SpoolerHasInitialized(void)
348 {
349 FIXME("() stub\n");
350 return TRUE;
351 }
352
353 /******************************************************************
354 * SpoolerInit [SPOOLSS.@]
355 */
356 BOOL WINAPI SpoolerInit(void)
357 {
358 FIXME("() stub\n");
359 return TRUE;
360 }
361
362 /******************************************************************
363 * WaitForSpoolerInitialization [SPOOLSS.@]
364 */
365 BOOL WINAPI WaitForSpoolerInitialization(void)
366 {
367 FIXME("() stub\n");
368 return TRUE;
369 }
370
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.