28977bdaeb79af5ccee1d5dd6fa1e8559a6869d8
[reactos.git] / win32ss / printing / base / winspool / ports.c
1 /*
2 * PROJECT: ReactOS Spooler API
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Functions related to Ports
5 * COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
6 */
7
8 #include "precomp.h"
9
10 static void
11 _MarshallUpPortInfo(PBYTE pPortInfo, DWORD Level)
12 {
13 PPORT_INFO_2W pPortInfo2 = (PPORT_INFO_2W)pPortInfo; // PORT_INFO_1W is a subset of PORT_INFO_2W
14
15 // Replace relative offset addresses in the output by absolute pointers.
16 pPortInfo2->pPortName = (PWSTR)((ULONG_PTR)pPortInfo2->pPortName + (ULONG_PTR)pPortInfo2);
17
18 if (Level == 2)
19 {
20 pPortInfo2->pDescription = (PWSTR)((ULONG_PTR)pPortInfo2->pDescription + (ULONG_PTR)pPortInfo2);
21 pPortInfo2->pMonitorName = (PWSTR)((ULONG_PTR)pPortInfo2->pMonitorName + (ULONG_PTR)pPortInfo2);
22 }
23 }
24
25 BOOL WINAPI
26 AddPortA(PSTR pName, HWND hWnd, PSTR pMonitorName)
27 {
28 TRACE("AddPortA(%s, %p, %s)\n", pName, hWnd, pMonitorName);
29 UNIMPLEMENTED;
30 return FALSE;
31 }
32
33 BOOL WINAPI
34 AddPortExA(PSTR pName, DWORD Level, PBYTE lpBuffer, PSTR lpMonitorName)
35 {
36 TRACE("AddPortExA(%s, %lu, %p, %s)\n", pName, Level, lpBuffer, lpMonitorName);
37 UNIMPLEMENTED;
38 return FALSE;
39 }
40
41 BOOL WINAPI
42 AddPortExW(PWSTR pName, DWORD Level, PBYTE lpBuffer, PWSTR lpMonitorName)
43 {
44 TRACE("AddPortExA(%S, %lu, %p, %S)\n", pName, Level, lpBuffer, lpMonitorName);
45 UNIMPLEMENTED;
46 return FALSE;
47 }
48
49 BOOL WINAPI
50 AddPortW(PWSTR pName, HWND hWnd, PWSTR pMonitorName)
51 {
52 TRACE("AddPortW(%S, %p, %S)\n", pName, hWnd, pMonitorName);
53 UNIMPLEMENTED;
54 return FALSE;
55 }
56
57 BOOL WINAPI
58 ConfigurePortA(PSTR pName, HWND hWnd, PSTR pPortName)
59 {
60 TRACE("ConfigurePortA(%s, %p, %s)\n", pName, hWnd, pPortName);
61 UNIMPLEMENTED;
62 return FALSE;
63 }
64
65 BOOL WINAPI
66 ConfigurePortW(PWSTR pName, HWND hWnd, PWSTR pPortName)
67 {
68 TRACE("ConfigurePortW(%S, %p, %S)\n", pName, hWnd, pPortName);
69 UNIMPLEMENTED;
70 return FALSE;
71 }
72
73 BOOL WINAPI
74 DeletePortA(PSTR pName, HWND hWnd, PSTR pPortName)
75 {
76 TRACE("DeletePortA(%s, %p, %s)\n", pName, hWnd, pPortName);
77 UNIMPLEMENTED;
78 return FALSE;
79 }
80
81 BOOL WINAPI
82 DeletePortW(PWSTR pName, HWND hWnd, PWSTR pPortName)
83 {
84 TRACE("DeletePortW(%S, %p, %S)\n", pName, hWnd, pPortName);
85 UNIMPLEMENTED;
86 return FALSE;
87 }
88
89 BOOL WINAPI
90 EnumPortsA(PSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
91 {
92 TRACE("EnumPortsA(%s, %lu, %p, %lu, %p, %p)\n", pName, Level, pPorts, cbBuf, pcbNeeded, pcReturned);
93 UNIMPLEMENTED;
94 return FALSE;
95 }
96
97 BOOL WINAPI
98 EnumPortsW(PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
99 {
100 DWORD dwErrorCode;
101 DWORD i;
102 PBYTE p = pPorts;
103
104 TRACE("EnumPortsW(%S, %lu, %p, %lu, %p, %p)\n", pName, Level, pPorts, cbBuf, pcbNeeded, pcReturned);
105
106 // Do the RPC call
107 RpcTryExcept
108 {
109 dwErrorCode = _RpcEnumPorts(pName, Level, pPorts, cbBuf, pcbNeeded, pcReturned);
110 }
111 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
112 {
113 dwErrorCode = RpcExceptionCode();
114 ERR("_RpcEnumPorts failed with exception code %lu!\n", dwErrorCode);
115 }
116 RpcEndExcept;
117
118 if (dwErrorCode == ERROR_SUCCESS)
119 {
120 // Replace relative offset addresses in the output by absolute pointers.
121 for (i = 0; i < *pcReturned; i++)
122 {
123 _MarshallUpPortInfo(p, Level);
124
125 if (Level == 1)
126 p += sizeof(PORT_INFO_1W);
127 else if (Level == 2)
128 p += sizeof(PORT_INFO_2W);
129 }
130 }
131
132 SetLastError(dwErrorCode);
133 return (dwErrorCode == ERROR_SUCCESS);
134 }
135
136 BOOL WINAPI
137 SetPortA(PSTR pName, PSTR pPortName, DWORD dwLevel, PBYTE pPortInfo)
138 {
139 TRACE("SetPortA(%s, %s, %lu, %p)\n", pName, pPortName, dwLevel, pPortInfo);
140 UNIMPLEMENTED;
141 return FALSE;
142 }
143
144 BOOL WINAPI
145 SetPortW(PWSTR pName, PWSTR pPortName, DWORD dwLevel, PBYTE pPortInfo)
146 {
147 TRACE("SetPortW(%S, %S, %lu, %p)\n", pName, pPortName, dwLevel, pPortInfo);
148 UNIMPLEMENTED;
149 return FALSE;
150 }