ReactOS 0.4.16-dev-303-g11d5cb8
xcv.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Print Spooler Service
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Xcv* functions
5 * COPYRIGHT: Copyright 2020 ReactOS
6 */
7
8#include "precomp.h"
9
10static DWORD
11_HandleAddPort(HANDLE hXcv, PBYTE pInputData, PDWORD pcbOutputNeeded, DWORD* pdwStatus)
12{
13 DWORD res;
14 PLOCAL_PRINT_MONITOR pPrintMonitor;
17 PWSTR pPortName = (PWSTR)pInputData;
18
19 FIXME("LocalXcvAddPort : %s\n", debugstr_w( pPortName ) );
20
21 // Check if this is a printer handle.
22 if (pHandle->HandleType != HandleType_Xcv)
23 {
24 ERR("LocalXcvAddPort : Invalid XCV Handle\n");
26 goto Cleanup;
27 }
28
29 pXcv = (PLOCAL_XCV_HANDLE)pHandle->pSpecificHandle;
30
31 pPrintMonitor = pXcv->pPrintMonitor;
32 if (!pPrintMonitor )
33 {
35 goto Cleanup;
36 }
37
38 // Sanity checks
39 if (!pInputData || !pcbOutputNeeded)
40 {
42 goto Cleanup;
43 }
44
45 pPrintMonitor->refcount++;
46 if ( pPrintMonitor->bIsLevel2 && ((PMONITOR2)pPrintMonitor->pMonitor)->pfnXcvDataPort )
47 {
48 res = ((PMONITOR2)pPrintMonitor->pMonitor)->pfnXcvDataPort(pXcv->hXcv, L"AddPort", pInputData, 0, NULL, 0, pcbOutputNeeded);
49 }
50 else if ( !pPrintMonitor->bIsLevel2 && ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnXcvDataPort )
51 {
52 res = ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnXcvDataPort(pXcv->hXcv, L"AddPort", pInputData, 0, NULL, 0, pcbOutputNeeded);
53 }
54 pPrintMonitor->refcount--;
55
56 if ( res == ERROR_SUCCESS )
57 {
58 CreatePortEntry( pPortName, pPrintMonitor );
59 }
60
61 FIXME("=> %u\n", res);
62
64 if (pdwStatus) *pdwStatus = res;
65 return res;
66}
67
68static DWORD
69_HandleDeletePort(HANDLE hXcv, PBYTE pInputData, PDWORD pcbOutputNeeded, DWORD* pdwStatus)
70{
71 DWORD res;
72 PLOCAL_PRINT_MONITOR pPrintMonitor;
74 PLOCAL_PORT pPort;
76 PWSTR pPortName = (PWSTR)pInputData;
77
78 FIXME("LocalXcvDeletePort : %s\n", debugstr_w( pPortName ) );
79
80 // Check if this is a printer handle.
81 if (pHandle->HandleType != HandleType_Xcv)
82 {
83 ERR("LocalXcvDeletePort : Invalid XCV Handle\n");
85 goto Cleanup;
86 }
87
88 pXcv = (PLOCAL_XCV_HANDLE)pHandle->pSpecificHandle;
89
90 pPrintMonitor = pXcv->pPrintMonitor;
91 if (!pPrintMonitor )
92 {
94 goto Cleanup;
95 }
96
97 // Sanity checks
98 if (!pInputData || !pcbOutputNeeded)
99 {
101 goto Cleanup;
102 }
103
104
105 pPrintMonitor->refcount++;
106 //
107 // Call back to monitor, update the Registry and Registry List.
108 //
109 if ( pPrintMonitor->bIsLevel2 && ((PMONITOR2)pPrintMonitor->pMonitor)->pfnXcvDataPort )
110 {
111 res = ((PMONITOR2)pPrintMonitor->pMonitor)->pfnXcvDataPort(pXcv->hXcv, L"DeletePort", pInputData, 0, NULL, 0, pcbOutputNeeded);
112 }
113 else if ( !pPrintMonitor->bIsLevel2 && ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnXcvDataPort )
114 {
115 res = ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnXcvDataPort(pXcv->hXcv, L"DeletePort", pInputData, 0, NULL, 0, pcbOutputNeeded);
116 }
117 pPrintMonitor->refcount--;
118 //
119 // Now find and remove Local Port data.
120 //
121 if ( res == ERROR_SUCCESS )
122 {
123 pPort = FindPort( pPortName );
124 if (pPort )
125 {
126 FIXME("LocalXcvDeletePort removed Port Entry\n");
127 RemoveEntryList(&pPort->Entry);
128
129 DllFreeSplMem(pPort);
130 }
131 FIXME("=> %u with %u\n", res, GetLastError() );
132 }
133
134Cleanup:
135 if (pdwStatus) *pdwStatus = res;
136 return res;
137}
138
140LocalXcvData(HANDLE hXcv, const WCHAR* pszDataName, BYTE* pInputData, DWORD cbInputData, BYTE* pOutputData, DWORD cbOutputData, DWORD* pcbOutputNeeded, DWORD* pdwStatus)
141{
142 DWORD res;
143 PLOCAL_PRINT_MONITOR pPrintMonitor;
146
147 FIXME("LocalXcvData(%p, %S, %p, %lu, %p, %lu, %p)\n", hXcv, pszDataName, pInputData, cbInputData, pOutputData, cbOutputData, pcbOutputNeeded);
148
149 // Sanity checks
150 if (!pszDataName)
151 {
153 goto Cleanup;
154 }
155
156 // Call the appropriate handler for the requested data name.
157 if (wcscmp(pszDataName, L"AddPort") == 0)
158 return _HandleAddPort(hXcv, pInputData, pcbOutputNeeded, pdwStatus);
159
160 if (wcscmp(pszDataName, L"DeletePort") == 0)
161 return _HandleDeletePort(hXcv, pInputData, pcbOutputNeeded, pdwStatus);
162
163 //
164 // After the two Intercept Handlers, defer call back to Monitor.
165 //
166
167 // Check if this is a printer handle.
168 if (pHandle->HandleType != HandleType_Xcv)
169 {
170 ERR("LocalXcvData : Invalid XCV Handle\n");
172 goto Cleanup;
173 }
174
175 pXcv = (PLOCAL_XCV_HANDLE)pHandle->pSpecificHandle;
176
177 pPrintMonitor = pXcv->pPrintMonitor;
178 if (!pPrintMonitor )
179 {
181 goto Cleanup;
182 }
183
184 pPrintMonitor->refcount++;
185 if ( pPrintMonitor->bIsLevel2 && ((PMONITOR2)pPrintMonitor->pMonitor)->pfnXcvDataPort )
186 {
187 res = ((PMONITOR2)pPrintMonitor->pMonitor)->pfnXcvDataPort(pXcv->hXcv, pszDataName, pInputData, cbInputData, pOutputData, cbOutputData, pcbOutputNeeded);
188 }
189 else if ( !pPrintMonitor->bIsLevel2 && ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnXcvDataPort )
190 {
191 res = ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnXcvDataPort(pXcv->hXcv, pszDataName, pInputData, cbInputData, pOutputData, cbOutputData, pcbOutputNeeded);
192 }
193 pPrintMonitor->refcount--;
194
195Cleanup:
197 if (pdwStatus) *pdwStatus = res;
198 return res;
199}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define ERR(fmt,...)
Definition: precomp.h:57
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
static const WCHAR Cleanup[]
Definition: register.c:80
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint res
Definition: glext.h:9613
#define debugstr_w
Definition: kernel32.h:32
if(dx< 0)
Definition: linetemp.h:194
static HANDLE hXcv
Definition: localmon.c:73
static DWORD _HandleDeletePort(PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:167
static DWORD _HandleAddPort(PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:11
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
DWORD * PDWORD
Definition: pedump.c:68
BOOL WINAPI LocalXcvData(HANDLE hXcv, const WCHAR *pszDataName, BYTE *pInputData, DWORD cbInputData, BYTE *pOutputData, DWORD cbOutputData, DWORD *pcbOutputNeeded, DWORD *pdwStatus)
Definition: xcv.c:140
struct _MONITOR2 * PMONITOR2
struct _MONITOREX * LPMONITOREX
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
@ Monitor
Definition: video.h:270
enum _LOCAL_HANDLE::@5124 HandleType
PVOID pSpecificHandle
Definition: precomp.h:208
LIST_ENTRY Entry
Definition: precomp.h:89
PLOCAL_PRINT_MONITOR pPrintMonitor
Definition: precomp.h:192
uint16_t * PWSTR
Definition: typedefs.h:56
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
BOOL CreatePortEntry(PCWSTR pwszName, PLOCAL_PRINT_MONITOR pPrintMonitor)
Definition: ports.c:37
PLOCAL_PORT FindPort(PCWSTR pwszName)
Definition: ports.c:15
struct _LOCAL_XCV_HANDLE * PLOCAL_XCV_HANDLE
Definition: precomp.h:64
struct _LOCAL_HANDLE * PLOCAL_HANDLE
Definition: precomp.h:56
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193