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