[SPOOLSS]
[reactos.git] / reactos / dll / win32 / spoolss / spoolss_main.c
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 #define WIN32_NO_STATUS
22
23 #include <stdarg.h>
24
25 //#include "windef.h"
26 //#include "winbase.h"
27 //#include "winerror.h"
28 //#include "winreg.h"
29
30 //#include "wingdi.h"
31 //#include "winspool.h"
32 //#include "ddk/winsplp.h"
33 #include "spoolss.h"
34
35 #include <wine/debug.h>
36
37 WINE_DEFAULT_DEBUG_CHANNEL(spoolss);
38
39 /* ################################ */
40
41 static HMODULE hwinspool;
42
43 static const WCHAR winspooldrvW[] = {'w','i','n','s','p','o','o','l','.','d','r','v',0};
44
45 /******************************************************************************
46 *
47 */
48 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
49 {
50 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
51
52 switch (fdwReason) {
53 case DLL_WINE_PREATTACH:
54 return FALSE; /* prefer native version */
55 case DLL_PROCESS_ATTACH: {
56 DisableThreadLibraryCalls(hinstDLL);
57 break;
58
59 case DLL_PROCESS_DETACH:
60 if (lpvReserved) break;
61 backend_unload_all();
62 break;
63 }
64 }
65 return TRUE;
66 }
67
68 /******************************************************************
69 * AllocSplStr [SPOOLSS.@]
70 *
71 * Create a copy from the String on the Spooler-Heap
72 *
73 * PARAMS
74 * pwstr [I] PTR to the String to copy
75 *
76 * RETURNS
77 * Failure: NULL
78 * Success: PTR to the copied String
79 *
80 */
81 LPWSTR WINAPI AllocSplStr(LPCWSTR pwstr)
82 {
83 LPWSTR res = NULL;
84 DWORD len;
85
86 TRACE("(%s)\n", debugstr_w(pwstr));
87 if (!pwstr) return NULL;
88
89 len = (lstrlenW(pwstr) + 1) * sizeof(WCHAR);
90 res = HeapAlloc(GetProcessHeap(), 0, len);
91 if (res) lstrcpyW(res, pwstr);
92
93 TRACE("returning %p\n", res);
94 return res;
95 }
96
97 /******************************************************************
98 * BuildOtherNamesFromMachineName [SPOOLSS.@]
99 */
100 BOOL WINAPI BuildOtherNamesFromMachineName(LPVOID * ptr1, LPVOID * ptr2)
101 {
102 FIXME("(%p, %p) stub\n", ptr1, ptr2);
103
104 *ptr1 = NULL;
105 *ptr2 = NULL;
106 return FALSE;
107 }
108
109 /******************************************************************
110 * DllAllocSplMem [SPOOLSS.@]
111 *
112 * Allocate cleared memory from the spooler heap
113 *
114 * PARAMS
115 * size [I] Number of bytes to allocate
116 *
117 * RETURNS
118 * Failure: NULL
119 * Success: PTR to the allocated memory
120 *
121 * NOTES
122 * We use the process heap (Windows use a separate spooler heap)
123 *
124 */
125 LPVOID WINAPI DllAllocSplMem(DWORD size)
126 {
127 LPVOID res;
128
129 res = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
130 TRACE("(%d) => %p\n", size, res);
131 return res;
132 }
133
134 /******************************************************************
135 * DllFreeSplMem [SPOOLSS.@]
136 *
137 * Free the allocated spooler memory
138 *
139 * PARAMS
140 * memory [I] PTR to the memory allocated by DllAllocSplMem
141 *
142 * RETURNS
143 * Failure: FALSE
144 * Success: TRUE
145 *
146 * NOTES
147 * We use the process heap (Windows use a separate spooler heap)
148 *
149 */
150
151 BOOL WINAPI DllFreeSplMem(LPBYTE memory)
152 {
153 TRACE("(%p)\n", memory);
154 return HeapFree(GetProcessHeap(), 0, memory);
155 }
156
157 /******************************************************************
158 * DllFreeSplStr [SPOOLSS.@]
159 *
160 * Free the allocated Spooler-String
161 *
162 * PARAMS
163 * pwstr [I] PTR to the WSTR, allocated by AllocSplStr
164 *
165 * RETURNS
166 * Failure: FALSE
167 * Success: TRUE
168 *
169 */
170
171 BOOL WINAPI DllFreeSplStr(LPWSTR pwstr)
172 {
173 TRACE("(%s) PTR: %p\n", debugstr_w(pwstr), pwstr);
174 return HeapFree(GetProcessHeap(), 0, pwstr);
175 }
176
177
178 /******************************************************************
179 * ImpersonatePrinterClient [SPOOLSS.@]
180 */
181 BOOL WINAPI ImpersonatePrinterClient(HANDLE hToken)
182 {
183 FIXME("(%p) stub\n", hToken);
184 return TRUE;
185 }
186
187 /******************************************************************
188 * InitializeRouter [SPOOLSS.@]
189 */
190 BOOL WINAPI InitializeRouter(void)
191 {
192 TRACE("()\n");
193 return backend_load_all();
194 }
195
196 /******************************************************************
197 * IsLocalCall [SPOOLSS.@]
198 */
199 BOOL WINAPI IsLocalCall(void)
200 {
201 FIXME("() stub\n");
202 return TRUE;
203 }
204
205 /******************************************************************
206 * RevertToPrinterSelf [SPOOLSS.@]
207 */
208 HANDLE WINAPI RevertToPrinterSelf(void)
209 {
210 FIXME("() stub\n");
211 return (HANDLE) 0xdead0947;
212 }
213
214 /******************************************************************
215 * SplInitializeWinSpoolDrv [SPOOLSS.@]
216 *
217 * Dynamic load "winspool.drv" and fill an array with some function-pointer
218 *
219 * PARAMS
220 * table [I] array of function-pointer to fill
221 *
222 * RETURNS
223 * Success: TRUE
224 * Failure: FALSE
225 *
226 * NOTES
227 * Native "spoolss.dll" from w2k fill the table with 11 Function-Pointer.
228 * We implement the XP-Version (The table has only 9 Pointer)
229 *
230 */
231 BOOL WINAPI SplInitializeWinSpoolDrv(LPVOID * table)
232 {
233 DWORD res;
234
235 TRACE("(%p)\n", table);
236
237 hwinspool = LoadLibraryW(winspooldrvW);
238 if (!hwinspool) return FALSE;
239
240 table[0] = (void *) GetProcAddress(hwinspool, "OpenPrinterW");
241 table[1] = (void *) GetProcAddress(hwinspool, "ClosePrinter");
242 table[2] = (void *) GetProcAddress(hwinspool, "SpoolerDevQueryPrintW");
243 table[3] = (void *) GetProcAddress(hwinspool, "SpoolerPrinterEvent");
244 table[4] = (void *) GetProcAddress(hwinspool, "DocumentPropertiesW");
245 table[5] = (void *) GetProcAddress(hwinspool, (LPSTR) 212); /* LoadPrinterDriver */
246 table[6] = (void *) GetProcAddress(hwinspool, (LPSTR) 213); /* RefCntLoadDriver */
247 table[7] = (void *) GetProcAddress(hwinspool, (LPSTR) 214); /* RefCntUnloadDriver */
248 table[8] = (void *) GetProcAddress(hwinspool, (LPSTR) 215); /* ForceUnloadDriver */
249
250 for (res = 0; res < 9; res++) {
251 if (table[res] == NULL) return FALSE;
252 }
253
254 return TRUE;
255
256 }
257
258 /******************************************************************
259 * SplIsUpgrade [SPOOLSS.@]
260 */
261 BOOL WINAPI SplIsUpgrade(void)
262 {
263 FIXME("() stub\n");
264 return FALSE;
265 }
266
267 /******************************************************************
268 * SpoolerHasInitialized [SPOOLSS.@]
269 */
270 BOOL WINAPI SpoolerHasInitialized(void)
271 {
272 FIXME("() stub\n");
273 return TRUE;
274 }
275
276 /******************************************************************
277 * SpoolerInit [SPOOLSS.@]
278 */
279 BOOL WINAPI SpoolerInit(void)
280 {
281 FIXME("() stub\n");
282 return TRUE;
283 }
284
285 /******************************************************************
286 * WaitForSpoolerInitialization [SPOOLSS.@]
287 */
288 BOOL WINAPI WaitForSpoolerInitialization(void)
289 {
290 FIXME("() stub\n");
291 return TRUE;
292 }