Assorted spelling fixes.
[wine.git] / dlls / spoolss / spoolss_main.c
blobcc4487c9fc84cbc89e054bce992f8162f0173b36
1 /*
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "winreg.h"
28 #include "wingdi.h"
29 #include "winspool.h"
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 =
41 0, 0, &backend_cs,
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")
65 * PARAMS
67 * RETURNS
68 * Success: TRUE
69 * Failure: FALSE and RPC_S_SERVER_UNAVAILABLE
71 * NOTES
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;
79 DWORD res;
81 if (backend) return TRUE;
83 EnterCriticalSection(&backend_cs);
84 hlocalspl = LoadLibraryW(localspldllW);
85 if (hlocalspl) {
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);
92 if (res) {
93 backend = &mybackend;
94 LeaveCriticalSection(&backend_cs);
95 TRACE("backend: %p (%p)\n", backend, hlocalspl);
96 return TRUE;
99 FreeLibrary(hlocalspl);
102 LeaveCriticalSection(&backend_cs);
104 WARN("failed to load the backend: %u\n", GetLastError());
105 SetLastError(RPC_S_SERVER_UNAVAILABLE);
106 return FALSE;
109 /******************************************************************
110 * unload_backend [internal]
113 static void backend_unload(void)
115 EnterCriticalSection(&backend_cs);
116 if (backend) {
117 backend = NULL;
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);
130 switch (fdwReason) {
131 case DLL_WINE_PREATTACH:
132 return FALSE; /* prefer native version */
133 case DLL_PROCESS_ATTACH: {
134 DisableThreadLibraryCalls(hinstDLL);
135 break;
137 case DLL_PROCESS_DETACH:
138 backend_unload();
139 break;
142 return TRUE;
145 /******************************************************************
146 * AllocSplStr [SPOOLSS.@]
148 * Create a copy from the String on the Spooler-Heap
150 * PARAMS
151 * pwstr [I] PTR to the String to copy
153 * RETURNS
154 * Failure: NULL
155 * Success: PTR to the copied String
158 LPWSTR WINAPI AllocSplStr(LPCWSTR pwstr)
160 LPWSTR res = NULL;
161 DWORD len;
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);
171 return res;
174 /******************************************************************
175 * BuildOtherNamesFromMachineName [SPOOLSS.@]
177 BOOL WINAPI BuildOtherNamesFromMachineName(LPVOID * ptr1, LPVOID * ptr2)
179 FIXME("(%p, %p) stub\n", ptr1, ptr2);
181 *ptr1 = NULL;
182 *ptr2 = NULL;
183 return FALSE;
186 /******************************************************************
187 * DllAllocSplMem [SPOOLSS.@]
189 * Allocate cleared memory from the spooler heap
191 * PARAMS
192 * size [I] Number of bytes to allocate
194 * RETURNS
195 * Failure: NULL
196 * Success: PTR to the allocated memory
198 * NOTES
199 * We use the process heap (Windows use a separate spooler heap)
202 LPVOID WINAPI DllAllocSplMem(DWORD size)
204 LPVOID res;
206 res = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
207 TRACE("(%d) => %p\n", size, res);
208 return res;
211 /******************************************************************
212 * DllFreeSplMem [SPOOLSS.@]
214 * Free the allocated spooler memory
216 * PARAMS
217 * memory [I] PTR to the memory allocated by DllAllocSplMem
219 * RETURNS
220 * Failure: FALSE
221 * Success: TRUE
223 * NOTES
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
239 * PARAMS
240 * pwstr [I] PTR to the WSTR, allocated by AllocSplStr
242 * RETURNS
243 * Failure: FALSE
244 * Success: TRUE
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);
261 return TRUE;
264 /******************************************************************
265 * InitializeRouter [SPOOLSS.@]
267 BOOL WINAPI InitializeRouter(void)
269 TRACE("()\n");
270 return backend_load();
273 /******************************************************************
274 * IsLocalCall [SPOOLSS.@]
276 BOOL WINAPI IsLocalCall(void)
278 FIXME("() stub\n");
279 return TRUE;
282 /******************************************************************
283 * RevertToPrinterSelf [SPOOLSS.@]
285 HANDLE WINAPI RevertToPrinterSelf(void)
287 FIXME("() stub\n");
288 return (HANDLE) 0xdead0947;
291 /******************************************************************
292 * SplInitializeWinSpoolDrv [SPOOLSS.@]
294 * Dynamic load "winspool.drv" and fill an array with some function-pointer
296 * PARAMS
297 * table [I] array of function-pointer to fill
299 * RETURNS
300 * Success: TRUE
301 * Failure: FALSE
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)
308 BOOL WINAPI SplInitializeWinSpoolDrv(LPVOID * table)
310 DWORD res;
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;
331 return TRUE;
335 /******************************************************************
336 * SplIsUpgrade [SPOOLSS.@]
338 BOOL WINAPI SplIsUpgrade(void)
340 FIXME("() stub\n");
341 return FALSE;
344 /******************************************************************
345 * SpoolerHasInitialized [SPOOLSS.@]
347 BOOL WINAPI SpoolerHasInitialized(void)
349 FIXME("() stub\n");
350 return TRUE;
353 /******************************************************************
354 * SpoolerInit [SPOOLSS.@]
356 BOOL WINAPI SpoolerInit(void)
358 FIXME("() stub\n");
359 return TRUE;
362 /******************************************************************
363 * WaitForSpoolerInitialization [SPOOLSS.@]
365 BOOL WINAPI WaitForSpoolerInitialization(void)
367 FIXME("() stub\n");
368 return TRUE;