ReactOS 0.4.15-dev-7934-g1dc8d80
ports.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Local Spooler
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Functions related to Ports of the Print Monitors
5 * COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
6 */
7
8#include "precomp.h"
9
10// Local Variables
12
13
16{
18 PLOCAL_PORT pPort;
19
20 TRACE("FindPort(%S)\n", pwszName);
21
22 if (!pwszName)
23 return NULL;
24
26 {
28
29 if (_wcsicmp(pPort->pwszName, pwszName) == 0)
30 return pPort;
31 }
32
33 return NULL;
34}
35
36BOOL
38{
39 PLOCAL_PORT pPort;
40 DWORD cbPortName = (wcslen( pwszName ) + 1) * sizeof(WCHAR);
41
42 // Create a new LOCAL_PORT structure for it.
43 pPort = DllAllocSplMem(sizeof(LOCAL_PORT) + cbPortName);
44 if (!pPort)
45 {
47 return FALSE;
48 }
49
50 pPort->pPrintMonitor = pPrintMonitor;
51 pPort->pwszName = wcscpy( (PWSTR)(pPort+1), pwszName );
52
53 // Insert it into the list and advance to the next port.
55
56 return TRUE;
57}
58
59BOOL
61{
62 BOOL bReturnValue;
63 DWORD cbNeeded;
64 DWORD cbPortName;
65 DWORD dwErrorCode;
66 DWORD dwReturned;
67 DWORD i;
68 PLOCAL_PORT pPort;
69 PLOCAL_PRINT_MONITOR pPrintMonitor;
72 PPORT_INFO_1W pPortInfo1 = NULL;
73
74 TRACE("InitializePortList()\n");
75
76 // Initialize an empty list for our Ports.
78
79 // Loop through all Print Monitors.
81 {
82 // Cleanup from the previous run.
83 if (pPortInfo1)
84 {
85 DllFreeSplMem(pPortInfo1);
86 pPortInfo1 = NULL;
87 }
88
90
91 // Determine the required buffer size for EnumPorts.
92 if (pPrintMonitor->bIsLevel2)
93 bReturnValue = ((PMONITOR2)pPrintMonitor->pMonitor)->pfnEnumPorts(pPrintMonitor->hMonitor, NULL, 1, NULL, 0, &cbNeeded, &dwReturned);
94 else
95 bReturnValue = ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnEnumPorts(NULL, 1, NULL, 0, &cbNeeded, &dwReturned);
96
97 // Check the returned error code.
99 {
100 ERR("Print Monitor \"%S\" failed with error %lu on EnumPorts!\n", pPrintMonitor->pwszName, GetLastError());
101 continue;
102 }
103
104 // Allocate a buffer large enough.
105 pPortInfo1 = DllAllocSplMem(cbNeeded);
106 if (!pPortInfo1)
107 {
108 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
109 ERR("DllAllocSplMem failed!\n");
110 goto Cleanup;
111 }
112
113 // Get the ports handled by this monitor.
114 if (pPrintMonitor->bIsLevel2)
115 bReturnValue = ((PMONITOR2)pPrintMonitor->pMonitor)->pfnEnumPorts(pPrintMonitor->hMonitor, NULL, 1, (PBYTE)pPortInfo1, cbNeeded, &cbNeeded, &dwReturned);
116 else
117 bReturnValue = ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnEnumPorts(NULL, 1, (PBYTE)pPortInfo1, cbNeeded, &cbNeeded, &dwReturned);
118
119 // Check the return value.
120 if (!bReturnValue)
121 {
122 ERR("Print Monitor \"%S\" failed with error %lu on EnumPorts!\n", pPrintMonitor->pwszName, GetLastError());
123 continue;
124 }
125
126 // Loop through all returned ports.
127 p = pPortInfo1;
128
129 for (i = 0; i < dwReturned; i++)
130 {
131 cbPortName = (wcslen(p->pName) + 1) * sizeof(WCHAR);
132
133 // Create a new LOCAL_PORT structure for it.
134 pPort = DllAllocSplMem(sizeof(LOCAL_PORT) + cbPortName);
135 if (!pPort)
136 {
137 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
138 ERR("DllAllocSplMem failed!\n");
139 goto Cleanup;
140 }
141
142 pPort->pPrintMonitor = pPrintMonitor;
143 pPort->pwszName = (PWSTR)((PBYTE)pPort + sizeof(LOCAL_PORT));
144 CopyMemory(pPort->pwszName, p->pName, cbPortName);
145
146 // Insert it into the list and advance to the next port.
147 InsertTailList(&_PortList, &pPort->Entry);
148 p++;
149 }
150 }
151
152 dwErrorCode = ERROR_SUCCESS;
153
154Cleanup:
155 // Inside the loop
156 if (pPortInfo1)
157 DllFreeSplMem(pPortInfo1);
158
159 SetLastError(dwErrorCode);
160 return (dwErrorCode == ERROR_SUCCESS);
161}
162
165{
166 BOOL bReturnValue = TRUE;
167 DWORD cbCallBuffer;
168 DWORD cbNeeded;
169 DWORD dwReturned;
170 PBYTE pCallBuffer;
171 PLOCAL_PRINT_MONITOR pPrintMonitor;
173
174 TRACE("LocalEnumPorts(%S, %lu, %p, %lu, %p, %p)\n", pName, Level, pPorts, cbBuf, pcbNeeded, pcReturned);
175
176 // Begin counting.
177 *pcbNeeded = 0;
178 *pcReturned = 0;
179
180 // At the beginning, we have the full buffer available.
181 cbCallBuffer = cbBuf;
182 pCallBuffer = pPorts;
183
184 // Loop through all Print Monitors.
186 {
188
189 // Call the EnumPorts function of this Print Monitor.
190 cbNeeded = 0;
191 dwReturned = 0;
192
193 if (pPrintMonitor->bIsLevel2)
194 bReturnValue = ((PMONITOR2)pPrintMonitor->pMonitor)->pfnEnumPorts(pPrintMonitor->hMonitor, pName, Level, pCallBuffer, cbCallBuffer, &cbNeeded, &dwReturned);
195 else
196 bReturnValue = ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnEnumPorts(pName, Level, pCallBuffer, cbCallBuffer, &cbNeeded, &dwReturned);
197
198 // Add the returned counts to the total values.
199 *pcbNeeded += cbNeeded;
200 *pcReturned += dwReturned;
201
202 // Reduce the available buffer size for the next call without risking an underflow.
203 if (cbNeeded < cbCallBuffer)
204 cbCallBuffer -= cbNeeded;
205 else
206 cbCallBuffer = 0;
207
208 // Advance the buffer if the caller provided it.
209 if (pCallBuffer)
210 pCallBuffer += cbNeeded;
211 }
212
213 return bReturnValue;
214}
215
218{
219 DWORD lres;
220 BOOL res = FALSE;
221 PLOCAL_PORT pPort;
222 PLOCAL_PRINT_MONITOR pPrintMonitor;
224
225 FIXME("LocalAddPortEx(%S, %lu, %p, %S)\n", pName, Level, lpBuffer, lpMonitorName);
226
228 if ( lres )
229 {
230 FIXME("server %s not supported\n", debugstr_w(pName));
232 return FALSE;
233 }
234
235 if ( Level != 1 )
236 {
238 return FALSE;
239 }
240
241 if ((!pi) || (!lpMonitorName) || (!lpMonitorName[0]))
242 {
244 return FALSE;
245 }
246
247 pPrintMonitor = FindPrintMonitor( lpMonitorName );
248 if (!pPrintMonitor )
249 {
251 return FALSE;
252 }
253
254 pPort = FindPort( pi->pName );
255 if ( pPort )
256 {
258 return FALSE;
259 }
260
261 if ( pPrintMonitor->bIsLevel2 && ((PMONITOR2)pPrintMonitor->pMonitor)->pfnAddPortEx )
262 {
263 res = ((PMONITOR2)pPrintMonitor->pMonitor)->pfnAddPortEx(pPrintMonitor->hMonitor, pName, Level, lpBuffer, lpMonitorName);
264 }
265 else if ( !pPrintMonitor->bIsLevel2 && ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnAddPortEx )
266 {
267 res = ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnAddPortEx(pName, Level, lpBuffer, lpMonitorName);
268 }
269 else
270 {
272 }
273
274 if ( res )
275 {
276 res = CreatePortEntry( pi->pName, pPrintMonitor );
277 }
278
279 return res;
280}
281
282//
283// Local (AP, CP & DP) is still around, seems to be a backup if a failure was encountered.. New way, WinSpool->LocalUI->XcvDataW.
284//
287{
288 DWORD lres;
289 BOOL res = FALSE;
290 PLOCAL_PRINT_MONITOR pPrintMonitor;
291
292 FIXME("LocalAddPort(%S, %p, %s)\n", pName, hWnd, debugstr_w(pMonitorName));
293
295 if (lres)
296 {
297 FIXME("server %s not supported\n", debugstr_w(pName));
299 return FALSE;
300 }
301
302 /* an empty Monitorname is Invalid */
303 if (!pMonitorName[0])
304 {
306 return FALSE;
307 }
308
309 pPrintMonitor = FindPrintMonitor( pMonitorName );
310 if (!pPrintMonitor )
311 {
313 return FALSE;
314 }
315
316 if ( pPrintMonitor->bIsLevel2 && ((PMONITOR2)pPrintMonitor->pMonitor)->pfnAddPort )
317 {
318 res = ((PMONITOR2)pPrintMonitor->pMonitor)->pfnAddPort(pPrintMonitor->hMonitor, pName, hWnd, pMonitorName);
319 }
320 else if ( !pPrintMonitor->bIsLevel2 && ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnAddPort )
321 {
322 res = ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnAddPort(pName, hWnd, pMonitorName);
323 }
324 else
325 {
327 }
328
329 if ( res )
330 {
331 DWORD cbNeeded, cReturned, i;
332 PPORT_INFO_1 pPorts;
333
334 //
335 // Play it safe,,, we know its Monitor2.... This is ReactOS.
336 //
337 if ( LocalEnumPorts( pName, 1, NULL, 0, &cbNeeded, &cReturned ) )
338 {
339 pPorts = DllAllocSplMem( cbNeeded );
340 if (pPorts)
341 {
342 if ( LocalEnumPorts( pName, 1, (PBYTE)pPorts, cbNeeded, &cbNeeded, &cReturned ) )
343 {
344 for ( i = 0; i < cReturned; i++ )
345 {
346 if ( !FindPort( pPorts[i].pName ) )
347 {
348 CreatePortEntry( pPorts[i].pName, pPrintMonitor );
349 }
350 }
351 }
352 DllFreeSplMem( pPorts );
353 }
354 }
355 }
356
357 return res;
358}
359
362{
363 LONG lres;
364 DWORD res;
365 PLOCAL_PORT pPrintPort;
366 PLOCAL_PRINT_MONITOR pPrintMonitor;
367
368 FIXME("LocalConfigurePort(%S, %p, %S)\n", pName, hWnd, pPortName);
369
371 if (lres)
372 {
373 FIXME("server %s not supported\n", debugstr_w(pName));
375 return FALSE;
376 }
377
378 /* an empty Portname is Invalid, but can popup a Dialog */
379 if (!pPortName[0])
380 {
382 return FALSE;
383 }
384
385 pPrintPort = FindPort(pPortName);
386 if (!pPrintPort )
387 {
389 return FALSE;
390 }
391
392 pPrintMonitor = pPrintPort->pPrintMonitor;
393
394 if ( pPrintMonitor->bIsLevel2 && ((PMONITOR2)pPrintMonitor->pMonitor)->pfnConfigurePort )
395 {
396 res = ((PMONITOR2)pPrintMonitor->pMonitor)->pfnConfigurePort(pPrintMonitor->hMonitor, pName, hWnd, pPortName);
397 }
398 else if ( !pPrintMonitor->bIsLevel2 && ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnConfigurePort )
399 {
400 res = ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnConfigurePort(pName, hWnd, pPortName);
401 }
402 else
403 {
405 }
406
407 return res;
408}
409
412{
413 LONG lres;
414 DWORD res = FALSE;
415 PLOCAL_PORT pPrintPort;
416 PLOCAL_PRINT_MONITOR pPrintMonitor;
417
418 FIXME("LocalDeletePort(%S, %p, %S)\n", pName, hWnd, pPortName);
419
421 if (lres)
422 {
423 FIXME("server %s not supported\n", debugstr_w(pName));
425 return FALSE;
426 }
427
428 if (!pPortName[0])
429 {
431 return FALSE;
432 }
433
434 pPrintPort = FindPort(pPortName);
435 if (!pPrintPort )
436 {
438 return FALSE;
439 }
440
441 pPrintMonitor = pPrintPort->pPrintMonitor;
442
443 if ( pPrintMonitor->bIsLevel2 && ((PMONITOR2)pPrintMonitor->pMonitor)->pfnDeletePort )
444 {
445 res = ((PMONITOR2)pPrintMonitor->pMonitor)->pfnDeletePort(pPrintMonitor->hMonitor, pName, hWnd, pPortName);
446 }
447 else if ( !pPrintMonitor->bIsLevel2 && ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnDeletePort )
448 {
449 res = ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnDeletePort(pName, hWnd, pPortName);
450 }
451
452 RemoveEntryList(&pPrintPort->Entry);
453
454 DllFreeSplMem(pPrintPort);
455
456 return res;
457}
458
460LocalSetPort(PWSTR pName, PWSTR pPortName, DWORD dwLevel, PBYTE pPortInfo)
461{
462 LONG lres;
463 DWORD res = 0;
464 PPORT_INFO_3W ppi3w = (PPORT_INFO_3W)pPortInfo;
465 PLOCAL_PORT pPrintPort;
466
467 TRACE("LocalSetPort(%S, %S, %lu, %p)\n", pName, pPortName, dwLevel, pPortInfo);
468
470 if (lres)
471 {
472 FIXME("server %s not supported\n", debugstr_w(pName));
474 return FALSE;
475 }
476
477 if ((dwLevel < 1) || (dwLevel > 2))
478 {
480 return FALSE;
481 }
482
483 if ( !ppi3w )
484 {
486 return FALSE;
487 }
488
489 pPrintPort = FindPort(pPortName);
490 if ( !pPrintPort )
491 {
493 return FALSE;
494 }
495
496 FIXME("Add Status Support to Local Ports!\n");
497
498 return res;
499}
HWND hWnd
Definition: settings.c:17
#define FIXME(fmt,...)
Definition: debug.h:111
#define ERR(fmt,...)
Definition: debug.h:110
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LOCAL_PORT
Definition: dhcpd.h:112
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_NOT_SUPPORTED
Definition: compat.h:100
#define ERROR_INVALID_NAME
Definition: compat.h:103
static const WCHAR Cleanup[]
Definition: register.c:80
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
GLuint res
Definition: glext.h:9613
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define debugstr_w
Definition: kernel32.h:32
static LPSTR pName
Definition: security.c:75
static refpint_t pi[]
Definition: server.c:96
BYTE * PBYTE
Definition: pedump.c:66
DWORD * PDWORD
Definition: pedump.c:68
long LONG
Definition: pedump.c:60
PLOCAL_PRINT_MONITOR FindPrintMonitor(PCWSTR pwszName)
Definition: monitors.c:28
LIST_ENTRY PrintMonitorList
Definition: monitors.c:11
struct _MONITOR2 * PMONITOR2
struct _MONITOREX * LPMONITOREX
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
@ Monitor
Definition: video.h:270
#define TRACE(s)
Definition: solgame.cpp:4
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
PWSTR pwszName
Definition: precomp.h:90
LIST_ENTRY Entry
Definition: precomp.h:89
PLOCAL_PRINT_MONITOR pPrintMonitor
Definition: precomp.h:91
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95
BOOL WINAPI LocalSetPort(PWSTR pName, PWSTR pPortName, DWORD dwLevel, PBYTE pPortInfo)
Definition: ports.c:460
BOOL WINAPI LocalConfigurePort(PWSTR pName, HWND hWnd, PWSTR pPortName)
Definition: ports.c:361
BOOL WINAPI LocalAddPort(LPWSTR pName, HWND hWnd, LPWSTR pMonitorName)
Definition: ports.c:286
BOOL CreatePortEntry(PCWSTR pwszName, PLOCAL_PRINT_MONITOR pPrintMonitor)
Definition: ports.c:37
BOOL InitializePortList(void)
Definition: ports.c:60
BOOL WINAPI LocalDeletePort(PWSTR pName, HWND hWnd, PWSTR pPortName)
Definition: ports.c:411
static LIST_ENTRY _PortList
Definition: ports.c:11
PLOCAL_PORT FindPort(PCWSTR pwszName)
Definition: ports.c:15
BOOL WINAPI LocalAddPortEx(PWSTR pName, DWORD Level, PBYTE lpBuffer, PWSTR lpMonitorName)
Definition: ports.c:217
BOOL WINAPI LocalEnumPorts(PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
Definition: ports.c:164
LONG copy_servername_from_name(LPCWSTR name, LPWSTR target)
Definition: tools.c:89
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CopyMemory
Definition: winbase.h:1710
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3828
#define WINAPI
Definition: msvc.h:6
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
#define ERROR_UNKNOWN_PORT
Definition: winerror.h:1103
struct _PORT_INFO_3W * PPORT_INFO_3W
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184