ReactOS 0.4.15-dev-8102-g108db8f
precomp.h File Reference
#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winreg.h>
#include <winspool.h>
#include <winsplp.h>
#include <winuser.h>
#include <ndk/rtlfuncs.h>
#include <spoolss.h>
#include <wine/debug.h>
#include "resource.h"
Include dependency graph for precomp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _LOCALMON_HANDLE
 
struct  _LOCALMON_PORT
 
struct  _LOCALMON_XCV
 

Macros

#define WIN32_NO_STATUS
 
#define SIGLCMMON   'FrCN'
 
#define SIGLCMPORT   'FrHK'
 

Typedefs

typedef struct _LOCALMON_HANDLE LOCALMON_HANDLE
 
typedef struct _LOCALMON_HANDLEPLOCALMON_HANDLE
 
typedef struct _LOCALMON_PORT LOCALMON_PORT
 
typedef struct _LOCALMON_PORTPLOCALMON_PORT
 
typedef struct _LOCALMON_XCV LOCALMON_XCV
 
typedef struct _LOCALMON_XCVPLOCALMON_XCV
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (localmon)
 
void WINAPI LocalmonShutdown (HANDLE hMonitor)
 
BOOL WINAPI LocalmonClosePort (HANDLE hPort)
 
BOOL WINAPI LocalmonEndDocPort (HANDLE hPort)
 
BOOL WINAPI LocalmonEnumPorts (HANDLE hMonitor, PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
 
BOOL WINAPI LocalmonGetPrinterDataFromPort (HANDLE hPort, DWORD ControlID, PWSTR pValueName, PWSTR lpInBuffer, DWORD cbInBuffer, PWSTR lpOutBuffer, DWORD cbOutBuffer, PDWORD lpcbReturned)
 
BOOL WINAPI LocalmonOpenPort (HANDLE hMonitor, PWSTR pName, PHANDLE pHandle)
 
BOOL WINAPI LocalmonReadPort (HANDLE hPort, PBYTE pBuffer, DWORD cbBuffer, PDWORD pcbRead)
 
BOOL WINAPI LocalmonSetPortTimeOuts (HANDLE hPort, LPCOMMTIMEOUTS lpCTO, DWORD Reserved)
 
BOOL WINAPI LocalmonStartDocPort (HANDLE hPort, PWSTR pPrinterName, DWORD JobId, DWORD Level, PBYTE pDocInfo)
 
BOOL WINAPI LocalmonWritePort (HANDLE hPort, PBYTE pBuffer, DWORD cbBuf, PDWORD pcbWritten)
 
BOOL WINAPI LocalmonAddPort (HANDLE hMonitor, LPWSTR pName, HWND hWnd, LPWSTR pMonitorName)
 
BOOL WINAPI LocalmonAddPortEx (HANDLE hMonitor, LPWSTR pName, DWORD Level, LPBYTE lpBuffer, LPWSTR lpMonitorName)
 
BOOL WINAPI LocalmonConfigurePort (HANDLE hMonitor, LPWSTR pName, HWND hWnd, LPWSTR pPortName)
 
BOOL WINAPI LocalmonDeletePort (HANDLE hMonitor, LPWSTR pName, HWND hWnd, LPWSTR pPortName)
 
BOOL DoesPortExist (PCWSTR pwszPortName)
 
DWORD GetLPTTransmissionRetryTimeout (VOID)
 
DWORD GetPortNameWithoutColon (PCWSTR pwszPortName, PWSTR *ppwszPortNameWithoutColon)
 
DWORD GetTypeFromName (LPCWSTR name)
 
BOOL WINAPI LocalmonXcvClosePort (HANDLE hXcv)
 
DWORD WINAPI LocalmonXcvDataPort (HANDLE hXcv, PCWSTR pszDataName, PBYTE pInputData, DWORD cbInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
 
BOOL WINAPI LocalmonXcvOpenPort (HANDLE hMonitor, PCWSTR pszObject, ACCESS_MASK GrantedAccess, PHANDLE phXcv)
 

Variables

DWORD cbLocalMonitor
 
DWORD cbLocalPort
 
PCWSTR pwszLocalMonitor
 
PCWSTR pwszLocalPort
 

Macro Definition Documentation

◆ SIGLCMMON

#define SIGLCMMON   'FrCN'

Definition at line 30 of file precomp.h.

◆ SIGLCMPORT

#define SIGLCMPORT   'FrHK'

Definition at line 31 of file precomp.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file precomp.h.

Typedef Documentation

◆ LOCALMON_HANDLE

Describes the monitor handle returned by InitializePrintMonitor2. Manages all available ports in this instance.

◆ LOCALMON_PORT

Describes the port handle returned by LocalmonOpenPort. Manages a legacy port (COM/LPT) or virtual FILE: port for printing as well as its associated printer and job.

◆ LOCALMON_XCV

Describes the Xcv handle returned by LocalmonXcvOpenPort. Manages the required data for the Xcv* calls.

◆ PLOCALMON_HANDLE

◆ PLOCALMON_PORT

◆ PLOCALMON_XCV

Function Documentation

◆ DoesPortExist()

BOOL DoesPortExist ( PCWSTR  pwszPortName)

Definition at line 24 of file tools.c.

25{
26 BOOL bReturnValue = FALSE;
27 DWORD cbNeeded;
28 DWORD dwErrorCode;
29 DWORD dwReturned;
30 DWORD i;
32 PPORT_INFO_1W pPortInfo1 = NULL;
33
34 // Determine the required buffer size.
35 EnumPortsW(NULL, 1, NULL, 0, &cbNeeded, &dwReturned);
37 {
38 dwErrorCode = GetLastError();
39 ERR("EnumPortsW failed with error %lu!\n", dwErrorCode);
40 goto Cleanup;
41 }
42
43 // Allocate a buffer large enough.
44 pPortInfo1 = DllAllocSplMem(cbNeeded);
45 if (!pPortInfo1)
46 {
47 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
48 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
49 goto Cleanup;
50 }
51
52 // Now get the actual port information.
53 if (!EnumPortsW(NULL, 1, (PBYTE)pPortInfo1, cbNeeded, &cbNeeded, &dwReturned))
54 {
55 dwErrorCode = GetLastError();
56 ERR("EnumPortsW failed with error %lu!\n", dwErrorCode);
57 goto Cleanup;
58 }
59
60 // We were successful! Loop through all returned ports.
61 dwErrorCode = ERROR_SUCCESS;
62 p = pPortInfo1;
63
64 for (i = 0; i < dwReturned; i++)
65 {
66 // Check if this existing port matches our queried one.
67 if (wcsicmp(p->pName, pwszPortName) == 0)
68 {
69 bReturnValue = TRUE;
70 goto Cleanup;
71 }
72
73 p++;
74 }
75
77 if (pPortInfo1)
78 DllFreeSplMem(pPortInfo1);
79
80 SetLastError(dwErrorCode);
81 return bReturnValue;
82}
#define ERR(fmt,...)
Definition: debug.h:113
#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 NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define SetLastError(x)
Definition: compat.h:752
#define wcsicmp
Definition: compat.h:15
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
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
BYTE * PBYTE
Definition: pedump.c:66
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
WINBOOL WINAPI EnumPortsW(LPWSTR pName, DWORD Level, LPBYTE pPorts, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)

Referenced by _HandleAddPort(), _HandlePortExists(), LocalmonAddPort(), and LocalmonAddPortEx().

◆ GetLPTTransmissionRetryTimeout()

DWORD GetLPTTransmissionRetryTimeout ( VOID  )

Definition at line 85 of file tools.c.

86{
87 DWORD cbBuffer;
88 DWORD dwReturnValue = 90; // Use 90 seconds as default if we fail to read from registry.
89 HKEY hKey;
90 LSTATUS lStatus;
91
92 // Six digits is the most you can enter in Windows' LocalUI.dll.
93 // Larger values make it crash, so introduce a limit here.
94 WCHAR wszBuffer[6 + 1];
95
96 // Open the key where our value is stored.
97 lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows", 0, KEY_READ, &hKey);
98 if (lStatus != ERROR_SUCCESS)
99 {
100 ERR("RegOpenKeyExW failed with status %ld!\n", lStatus);
101 goto Cleanup;
102 }
103
104 // Query the value.
105 cbBuffer = sizeof(wszBuffer);
106 lStatus = RegQueryValueExW(hKey, L"TransmissionRetryTimeout", NULL, NULL, (PBYTE)wszBuffer, &cbBuffer);
107 if (lStatus != ERROR_SUCCESS)
108 {
109 ERR("RegQueryValueExW failed with status %ld!\n", lStatus);
110 goto Cleanup;
111 }
112
113 // Return it converted to a DWORD.
114 dwReturnValue = wcstoul(wszBuffer, NULL, 10);
115
116Cleanup:
117 if (hKey)
119
120 return dwReturnValue;
121}
#define RegCloseKey(hKey)
Definition: registry.h:49
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
FxAutoRegKey hKey
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define KEY_READ
Definition: nt_native.h:1023
#define L(x)
Definition: ntvdm.h:50
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by _HandleGetTransmissionRetryTimeout(), and _SetTransmissionRetryTimeout().

◆ GetPortNameWithoutColon()

DWORD GetPortNameWithoutColon ( PCWSTR  pwszPortName,
PWSTR ppwszPortNameWithoutColon 
)

Definition at line 142 of file tools.c.

143{
144 DWORD cchPortNameWithoutColon;
145
146 // Compute the string length of pwszPortNameWithoutColon.
147 cchPortNameWithoutColon = wcslen(pwszPortName) - 1;
148
149 // Check if pwszPortName really has a colon as the last character.
150 if (pwszPortName[cchPortNameWithoutColon] != L':')
152
153 // Allocate the output buffer.
154 *ppwszPortNameWithoutColon = DllAllocSplMem((cchPortNameWithoutColon + 1) * sizeof(WCHAR));
155 if (!*ppwszPortNameWithoutColon)
156 {
157 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
159 }
160
161 // Copy the port name without colon into the buffer.
162 // The buffer is already zero-initialized, so no additional null-termination is necessary.
163 CopyMemory(*ppwszPortNameWithoutColon, pwszPortName, cchPortNameWithoutColon * sizeof(WCHAR));
164
165 return ERROR_SUCCESS;
166}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define CopyMemory
Definition: winbase.h:1710

Referenced by _ClosePortHandles(), _CreateNonspooledPort(), and _HandleSetDefaultCommConfig().

◆ GetTypeFromName()

DWORD GetTypeFromName ( LPCWSTR  name)

Definition at line 215 of file tools.c.

216{
217 HANDLE hfile;
218
219 if (!wcsncmp(name, L"LPT", ARRAYSIZE(L"LPT") - 1) )
220 return PORT_IS_LPT;
221
222 if (!wcsncmp(name, L"COM", ARRAYSIZE(L"COM") - 1) )
223 return PORT_IS_COM;
224
225 if (!lstrcmpW(name, L"FILE:") )
226 return PORT_IS_FILE;
227
228// if (name[0] == '/')
229// return PORT_IS_UNIXNAME;
230
231// if (name[0] == '|')
232// return PORT_IS_PIPE;
233
234 if ( _IsNEPort( name ) )
235 return PORT_IS_VNET;
236
237 if (!wcsncmp(name, L"XPS", ARRAYSIZE(L"XPS") - 1))
238 return PORT_IS_XPS;
239
240 /* Must be a file or a directory. Does the file exist ? */
242
243 FIXME("%p for OPEN_EXISTING on %s\n", hfile, debugstr_w(name));
244
245 if (hfile == INVALID_HANDLE_VALUE)
246 {
247 /* Can we create the file? */
249 FIXME("%p for OPEN_ALWAYS\n", hfile);
250 }
251
252 if (hfile != INVALID_HANDLE_VALUE)
253 {
254 CloseHandle(hfile); FIXME("PORT_IS_FILENAME %d\n",PORT_IS_FILENAME);
255 return PORT_IS_FILENAME;
256 }
257 FIXME("PORT_IS_UNKNOWN %d\n",PORT_IS_UNKNOWN);
258 /* We can't use the name. use GetLastError() for the reason */
259 return PORT_IS_UNKNOWN;
260}
#define FIXME(fmt,...)
Definition: debug.h:114
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4242
#define debugstr_w
Definition: kernel32.h:32
#define FILE_FLAG_DELETE_ON_CLOSE
Definition: disk.h:42
#define OPEN_ALWAYS
Definition: disk.h:70
static __inline BOOL _IsNEPort(PCWSTR pwszPortName)
Definition: tools.c:183
#define GENERIC_WRITE
Definition: nt_native.h:90
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define PORT_IS_XPS
Definition: spoolss.h:23
#define PORT_IS_LPT
Definition: spoolss.h:15
#define PORT_IS_COM
Definition: spoolss.h:16
#define PORT_IS_FILE
Definition: spoolss.h:17
#define PORT_IS_FILENAME
Definition: spoolss.h:18
#define PORT_IS_VNET
Definition: spoolss.h:22
#define PORT_IS_UNKNOWN
Definition: spoolss.h:14
Definition: name.c:39

Referenced by _HandlePortIsValid().

◆ LocalmonAddPort()

BOOL WINAPI LocalmonAddPort ( HANDLE  hMonitor,
LPWSTR  pName,
HWND  hWnd,
LPWSTR  pMonitorName 
)

Definition at line 1137 of file ports.c.

1138{
1139 DWORD res, cbPortName;
1140 HKEY hroot;
1141 PLOCALMON_HANDLE pLocalmon = (PLOCALMON_HANDLE)hMonitor;
1142 PLOCALMON_PORT pPort;
1143 WCHAR PortName[MAX_PATH] = {0}; // Need to use a Dialog to get name.
1144
1145 FIXME("LocalmonAddPort : %s\n", debugstr_w( (LPWSTR) pMonitorName ) );
1146
1147 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Ports", &hroot);
1148 if (res == ERROR_SUCCESS)
1149 {
1150 if ( DoesPortExist( PortName ) )
1151 {
1152 RegCloseKey(hroot);
1153 FIXME("=> %u\n", ERROR_ALREADY_EXISTS);
1155 goto Cleanup;
1156 }
1157
1158 cbPortName = (wcslen( PortName ) + 1) * sizeof(WCHAR);
1159
1160 // Create a new LOCALMON_PORT structure for it.
1161 pPort = DllAllocSplMem(sizeof(LOCALMON_PORT) + cbPortName);
1162 if (!pPort)
1163 {
1165 RegCloseKey( hroot );
1166 goto Cleanup;
1167 }
1168
1169 pPort->Sig = SIGLCMPORT;
1170 pPort->hFile = INVALID_HANDLE_VALUE;
1171 pPort->pLocalmon = pLocalmon;
1172 pPort->pwszPortName = wcscpy( (PWSTR)(pPort+1), PortName );
1173
1174 // Insert it into the Registry list.
1175 InsertTailList(&pLocalmon->RegistryPorts, &pPort->Entry);
1176
1177 res = RegSetValueExW(hroot, PortName, 0, REG_SZ, (const BYTE *) L"", sizeof(L""));
1178 RegCloseKey(hroot);
1179 }
1180
1181 FIXME("=> %u\n", res);
1182
1183Cleanup:
1185 return (res == ERROR_SUCCESS);
1186}
static UNICODE_STRING PortName
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3268
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
#define MAX_PATH
Definition: compat.h:34
#define InsertTailList(ListHead, Entry)
GLuint res
Definition: glext.h:9613
#define REG_SZ
Definition: layer.c:22
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
LIST_ENTRY RegistryPorts
Definition: precomp.h:43
PWSTR pwszPortName
Definition: precomp.h:55
DWORD Sig
Definition: precomp.h:57
PLOCALMON_HANDLE pLocalmon
Definition: precomp.h:56
LIST_ENTRY Entry
Definition: precomp.h:54
HANDLE hFile
Definition: precomp.h:67
uint16_t * PWSTR
Definition: typedefs.h:56
#define SIGLCMPORT
Definition: precomp.h:31
struct _LOCALMON_HANDLE * PLOCALMON_HANDLE
BOOL DoesPortExist(PCWSTR pwszPortName)
Definition: tools.c:24
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned char BYTE
Definition: xxhash.c:193

◆ LocalmonAddPortEx()

BOOL WINAPI LocalmonAddPortEx ( HANDLE  hMonitor,
LPWSTR  pName,
DWORD  Level,
LPBYTE  lpBuffer,
LPWSTR  lpMonitorName 
)

Definition at line 1054 of file ports.c.

1055{
1056 PLOCALMON_HANDLE pLocalmon = (PLOCALMON_HANDLE)hMonitor;
1057 PLOCALMON_PORT pPort;
1058 HKEY hKey;
1059 DWORD dwErrorCode, cbPortName;
1061
1062 FIXME("LocalmonAddPortEx(%p, %lu, %p, %s) => %s\n", hMonitor, Level, lpBuffer, debugstr_w(lpMonitorName), debugstr_w(pi ? pi->pName : NULL));
1063
1064 // Sanity checks
1065 if ( !pLocalmon )
1066 {
1067 dwErrorCode = ERROR_INVALID_PARAMETER;
1068 goto Cleanup;
1069 }
1070
1071 if ( ( lpMonitorName == NULL ) ||
1072 ( lstrcmpiW( lpMonitorName, L"Local Port" ) != 0 ) ||
1073 ( pi == NULL ) ||
1074 ( pi->pName == NULL ) ||
1075 ( pi->pName[0] == '\0' ) )
1076 {
1077 ERR("Fail Monitor Port Name\n");
1079 return FALSE;
1080 }
1081
1082 if ( Level != 1 )
1083 {
1085 return FALSE;
1086 }
1087
1088 dwErrorCode = RegOpenKeyW( HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Ports", &hKey );
1089 if ( dwErrorCode == ERROR_SUCCESS )
1090 {
1091 if ( DoesPortExist( pi->pName ) )
1092 {
1093 RegCloseKey( hKey) ;
1094 FIXME("Port Exist => FALSE with %u\n", ERROR_INVALID_PARAMETER);
1096 return FALSE;
1097 }
1098
1099 cbPortName = (wcslen( pi->pName ) + 1) * sizeof(WCHAR);
1100
1101 // Create a new LOCALMON_PORT structure for it.
1102 pPort = DllAllocSplMem(sizeof(LOCALMON_PORT) + cbPortName);
1103 if (!pPort)
1104 {
1105 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1106 RegCloseKey( hKey );
1107 goto Cleanup;
1108 }
1109
1110 pPort->Sig = SIGLCMPORT;
1111 pPort->hFile = INVALID_HANDLE_VALUE;
1112 pPort->pLocalmon = pLocalmon;
1113 pPort->pwszPortName = wcscpy( (PWSTR)(pPort+1), pi->pName );
1114
1115 // Insert it into the Registry list.
1116 InsertTailList(&pLocalmon->RegistryPorts, &pPort->Entry);
1117
1118 dwErrorCode = RegSetValueExW( hKey, pi->pName, 0, REG_SZ, (const BYTE *) L"", sizeof(L"") );
1119 RegCloseKey( hKey );
1120 }
1121
1122Cleanup:
1124
1125 FIXME("LocalmonAddPortEx => %u with %u\n", (dwErrorCode == ERROR_SUCCESS), GetLastError());
1126
1127 return (dwErrorCode == ERROR_SUCCESS);
1128}
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4261
static refpint_t pi[]
Definition: server.c:96
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56

◆ LocalmonClosePort()

BOOL WINAPI LocalmonClosePort ( HANDLE  hPort)

Definition at line 456 of file ports.c.

457{
458 PLOCALMON_PORT pPort = (PLOCALMON_PORT)hPort;
459
460 TRACE("LocalmonClosePort(%p)\n", hPort);
461
462 // Sanity checks
463 if (!pPort)
464 {
466 return FALSE;
467 }
468
469 // Close the file handle, free memory for pwszMapping and delete any NONSPOOLED port.
470 _ClosePortHandles(pPort);
471
472 // Close any open printer handle.
473 if (pPort->hPrinter)
474 {
475 ClosePrinter(pPort->hPrinter);
476 pPort->hPrinter = NULL;
477 }
478
479 // Free virtual FILE: ports which were created in LocalmonOpenPort.
480 if (pPort->PortType == PortType_FILE)
481 {
483 RemoveEntryList(&pPort->Entry);
485 DllFreeSplMem(pPort);
486 }
487
489 return TRUE;
490}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define TRACE(s)
Definition: solgame.cpp:4
CRITICAL_SECTION Section
Definition: precomp.h:40
enum _LOCALMON_PORT::@5126 PortType
HANDLE hPrinter
Definition: precomp.h:68
static void _ClosePortHandles(PLOCALMON_PORT pPort)
Definition: ports.c:113
struct _LOCALMON_PORT * PLOCALMON_PORT
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
WINBOOL WINAPI ClosePrinter(HANDLE hPrinter)
Definition: printers.c:176

Referenced by LocalmonShutdown().

◆ LocalmonConfigurePort()

BOOL WINAPI LocalmonConfigurePort ( HANDLE  hMonitor,
LPWSTR  pName,
HWND  hWnd,
LPWSTR  pPortName 
)

Definition at line 1189 of file ports.c.

1190{
1192 FIXME("LocalmonConfigurePort : %s\n", debugstr_w( pPortName ) );
1193 return FALSE;
1194}

◆ LocalmonDeletePort()

BOOL WINAPI LocalmonDeletePort ( HANDLE  hMonitor,
LPWSTR  pName,
HWND  hWnd,
LPWSTR  pPortName 
)

Definition at line 1197 of file ports.c.

1198{
1199 DWORD res;
1200 HKEY hroot;
1201 PLOCALMON_HANDLE pLocalmon = (PLOCALMON_HANDLE)hMonitor;
1202 PLOCALMON_PORT pPort;
1203
1204 FIXME("LocalmonDeletePort : %s\n", debugstr_w( pPortName ) );
1205
1206 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Ports", &hroot);
1207 if ( res == ERROR_SUCCESS )
1208 {
1209 res = RegDeleteValueW(hroot, pPortName );
1210
1211 RegCloseKey(hroot);
1212
1213 pPort = _FindPort( pLocalmon, pPortName );
1214 if ( pPort )
1215 {
1217 RemoveEntryList(&pPort->Entry);
1219
1220 DllFreeSplMem(pPort);
1221 }
1222
1223 FIXME("=> %u with %u\n", res, GetLastError() );
1224 }
1225
1227 return (res == ERROR_SUCCESS);
1228}
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
static PLOCALMON_PORT _FindPort(PLOCALMON_HANDLE pLocalmon, PCWSTR pwszPortName)
Definition: ports.c:356

◆ LocalmonEndDocPort()

BOOL WINAPI LocalmonEndDocPort ( HANDLE  hPort)

Definition at line 493 of file ports.c.

494{
495 PLOCALMON_PORT pPort = (PLOCALMON_PORT)hPort;
496
497 TRACE("LocalmonEndDocPort(%p)\n", hPort);
498
499 // Sanity checks
500 if (!pPort)
501 {
503 return FALSE;
504 }
505
506 // Ending a document requires starting it first :-P
507 if (pPort->bStartedDoc)
508 {
509 // Close all ports opened in StartDocPort.
510 // That is, all but physical LPT ports (opened in OpenPort).
511 if (pPort->PortType != PortType_PhysicalLPT)
512 _ClosePortHandles(pPort);
513
514 // Report our progress.
516
517 // We're done with the printer.
518 ClosePrinter(pPort->hPrinter);
519 pPort->hPrinter = NULL;
520
521 // A new document can now be started again.
522 pPort->bStartedDoc = FALSE;
523 }
524
526 return TRUE;
527}
DWORD dwJobID
Definition: precomp.h:66
BOOL bStartedDoc
Definition: precomp.h:65
WINBOOL WINAPI SetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, LPBYTE pJob, DWORD Command)
#define JOB_CONTROL_SENT_TO_PRINTER
Definition: winspool.h:335

◆ LocalmonEnumPorts()

BOOL WINAPI LocalmonEnumPorts ( HANDLE  hMonitor,
PWSTR  pName,
DWORD  Level,
PBYTE  pPorts,
DWORD  cbBuf,
PDWORD  pcbNeeded,
PDWORD  pcReturned 
)

Definition at line 530 of file ports.c.

531{
532 DWORD dwErrorCode;
533 PBYTE pPortInfoEnd;
535 PLOCALMON_HANDLE pLocalmon = (PLOCALMON_HANDLE)hMonitor;
536 PLOCALMON_PORT pPort;
537
538 TRACE("LocalmonEnumPorts(%p, %S, %lu, %p, %lu, %p, %p)\n", hMonitor, pName, Level, pPorts, cbBuf, pcbNeeded, pcReturned);
539
540 // Windows Server 2003's Local Port Monitor does absolutely no sanity checks here, not even for the Level parameter.
541 // As we implement a more modern MONITOR2-based Port Monitor, check at least our hMonitor.
542 if (!pLocalmon)
543 {
544 dwErrorCode = ERROR_INVALID_HANDLE;
545 goto Cleanup;
546 }
547
548 // Begin counting.
549 *pcbNeeded = 0;
550 *pcReturned = 0;
551
552 EnterCriticalSection(&pLocalmon->Section);
553
554 // Count the required buffer size and the number of ports.
555 for (pEntry = pLocalmon->RegistryPorts.Flink; pEntry != &pLocalmon->RegistryPorts; pEntry = pEntry->Flink)
556 {
558
559 if (Level == 1)
561 else if (Level == 2)
563 }
564
565 // Check if the supplied buffer is large enough.
566 if (cbBuf < *pcbNeeded)
567 {
568 LeaveCriticalSection(&pLocalmon->Section);
569 dwErrorCode = ERROR_INSUFFICIENT_BUFFER;
570 goto Cleanup;
571 }
572
573 // Copy over the Port information.
574 pPortInfoEnd = &pPorts[*pcbNeeded];
575
576 for (pEntry = pLocalmon->RegistryPorts.Flink; pEntry != &pLocalmon->RegistryPorts; pEntry = pEntry->Flink)
577 {
579
580 if (Level == 1)
581 _LocalmonGetPortLevel1(pPort, (PPORT_INFO_1W*)&pPorts, &pPortInfoEnd, NULL);
582 else if (Level == 2)
583 _LocalmonGetPortLevel2(pPort, (PPORT_INFO_2W*)&pPorts, &pPortInfoEnd, NULL);
584
585 (*pcReturned)++;
586 }
587
588 LeaveCriticalSection(&pLocalmon->Section);
589 dwErrorCode = ERROR_SUCCESS;
590
591Cleanup:
592 SetLastError(dwErrorCode);
593 return (dwErrorCode == ERROR_SUCCESS);
594}
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
static LPSTR pName
Definition: security.c:75
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
static void _LocalmonGetPortLevel2(PLOCALMON_PORT pPort, PPORT_INFO_2W *ppPortInfo, PBYTE *ppPortInfoEnd, PDWORD pcbNeeded)
Definition: ports.c:396
static void _LocalmonGetPortLevel1(PLOCALMON_PORT pPort, PPORT_INFO_1W *ppPortInfo, PBYTE *ppPortInfoEnd, PDWORD pcbNeeded)
Definition: ports.c:373
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3828

◆ LocalmonGetPrinterDataFromPort()

BOOL WINAPI LocalmonGetPrinterDataFromPort ( HANDLE  hPort,
DWORD  ControlID,
PWSTR  pValueName,
PWSTR  lpInBuffer,
DWORD  cbInBuffer,
PWSTR  lpOutBuffer,
DWORD  cbOutBuffer,
PDWORD  lpcbReturned 
)

Definition at line 630 of file ports.c.

631{
632 BOOL bOpenedPort = FALSE;
633 DWORD dwErrorCode;
634 PLOCALMON_PORT pPort = (PLOCALMON_PORT)hPort;
635
636 TRACE("LocalmonGetPrinterDataFromPort(%p, %lu, %p, %p, %lu, %p, %lu, %p)\n", hPort, ControlID, pValueName, lpInBuffer, cbInBuffer, lpOutBuffer, cbOutBuffer, lpcbReturned);
637
638 // Sanity checks
639 if (!pPort || !ControlID || !lpcbReturned)
640 {
641 dwErrorCode = ERROR_INVALID_PARAMETER;
642 goto Cleanup;
643 }
644
645 // If this is a serial port, a temporary file handle may be opened.
646 if (pPort->PortType == PortType_PhysicalCOM)
647 {
648 if (_CreateNonspooledPort(pPort))
649 {
650 bOpenedPort = TRUE;
651 }
652 else if (GetLastError() != ERROR_SUCCESS)
653 {
654 dwErrorCode = GetLastError();
655 goto Cleanup;
656 }
657 }
658 else if (pPort->hFile == INVALID_HANDLE_VALUE)
659 {
660 // All other port types need to be opened already.
661 dwErrorCode = ERROR_INVALID_PARAMETER;
662 goto Cleanup;
663 }
664
665 // Pass the parameters to DeviceIoControl.
666 if (!DeviceIoControl(pPort->hFile, ControlID, lpInBuffer, cbInBuffer, lpOutBuffer, cbOutBuffer, lpcbReturned, NULL))
667 {
668 dwErrorCode = GetLastError();
669 ERR("DeviceIoControl failed with error %lu!\n", dwErrorCode);
670 goto Cleanup;
671 }
672
673 dwErrorCode = ERROR_SUCCESS;
674
675Cleanup:
676 if (bOpenedPort)
677 _ClosePortHandles(pPort);
678
679 SetLastError(dwErrorCode);
680 return (dwErrorCode == ERROR_SUCCESS);
681}
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
static BOOL _CreateNonspooledPort(PLOCALMON_PORT pPort)
Definition: ports.c:162

◆ LocalmonOpenPort()

BOOL WINAPI LocalmonOpenPort ( HANDLE  hMonitor,
PWSTR  pName,
PHANDLE  pHandle 
)

Definition at line 684 of file ports.c.

685{
686 DWORD dwErrorCode;
687 PLOCALMON_HANDLE pLocalmon = (PLOCALMON_HANDLE)hMonitor;
688 PLOCALMON_PORT pPort;
689
690 TRACE("LocalmonOpenPort(%p, %S, %p)\n", hMonitor, pName, pHandle);
691
692 // Sanity checks
693 if (!pLocalmon || !pName || !pHandle)
694 {
695 dwErrorCode = ERROR_INVALID_PARAMETER;
696 goto Cleanup;
697 }
698
699 EnterCriticalSection(&pLocalmon->Section);
700
701 // Check if this is a FILE: port.
702 if (_wcsicmp(pName, L"FILE:") == 0)
703 {
704 // For FILE:, we create a virtual port for each request.
705 pPort = DllAllocSplMem(sizeof(LOCALMON_PORT));
706 pPort->pLocalmon = pLocalmon;
707 pPort->PortType = PortType_FILE;
709
710 // Add it to the list of file ports.
711 InsertTailList(&pLocalmon->FilePorts, &pPort->Entry);
712 }
713 else
714 {
715 // Check if the port name is valid.
716 pPort = _FindPort(pLocalmon, pName);
717 if (!pPort)
718 {
719 LeaveCriticalSection(&pLocalmon->Section);
720 dwErrorCode = ERROR_UNKNOWN_PORT;
721 goto Cleanup;
722 }
723
724 // Even if this API is called OpenPort, port file handles aren't always opened here :-P
725 // Windows only does this for physical LPT ports here to enable bidirectional communication with the printer outside of jobs (using ReadPort and WritePort).
726 // The others are only opened per job in StartDocPort.
727 if (_IsLegacyPort(pName, L"LPT"))
728 {
729 // Try to create a NONSPOOLED port and open it.
730 if (_CreateNonspooledPort(pPort))
731 {
732 // Set the transmission retry timeout for the ReadPort and WritePort calls.
733 // This also checks if this port is a physical one.
735 {
736 // This is definitely a physical LPT port!
737 pPort->PortType = PortType_PhysicalLPT;
738 }
739 else
740 {
741 // This is no physical port, so don't keep its handle open.
742 _ClosePortHandles(pPort);
743 }
744 }
745 else if (GetLastError() != ERROR_SUCCESS)
746 {
747 LeaveCriticalSection(&pLocalmon->Section);
748 dwErrorCode = GetLastError();
749 goto Cleanup;
750 }
751 }
752 else if (_IsLegacyPort(pName, L"COM"))
753 {
754 // COM ports can't be redirected over the network, so this is a physical one.
755 pPort->PortType = PortType_PhysicalCOM;
756 }
757 }
758
759 LeaveCriticalSection(&pLocalmon->Section);
760
761 // Return our fetched LOCALMON_PORT structure in the handle.
762 *pHandle = (PHANDLE)pPort;
763 dwErrorCode = ERROR_SUCCESS;
764
765Cleanup:
766 SetLastError(dwErrorCode);
767 return (dwErrorCode == ERROR_SUCCESS);
768}
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
LIST_ENTRY FilePorts
Definition: precomp.h:42
static BOOL _SetTransmissionRetryTimeout(PLOCALMON_PORT pPort)
Definition: ports.c:440
static __inline BOOL _IsLegacyPort(PCWSTR pwszPortName, PCWSTR pwszPortType)
Definition: ports.c:79
#define ERROR_UNKNOWN_PORT
Definition: winerror.h:1103

◆ LocalmonReadPort()

BOOL WINAPI LocalmonReadPort ( HANDLE  hPort,
PBYTE  pBuffer,
DWORD  cbBuffer,
PDWORD  pcbRead 
)

Definition at line 843 of file ports.c.

844{
845 BOOL bOpenedPort = FALSE;
846 DWORD dwErrorCode;
847 PLOCALMON_PORT pPort = (PLOCALMON_PORT)hPort;
848
849 TRACE("LocalmonReadPort(%p, %p, %lu, %p)\n", hPort, pBuffer, cbBuffer, pcbRead);
850
851 // Sanity checks
852 if (!pPort || (cbBuffer && !pBuffer) || !pcbRead)
853 {
854 dwErrorCode = ERROR_INVALID_PARAMETER;
855 goto Cleanup;
856 }
857
858 // Reading is only supported for physical ports.
859 if (pPort->PortType != PortType_PhysicalCOM && pPort->PortType != PortType_PhysicalLPT)
860 {
861 dwErrorCode = ERROR_INVALID_HANDLE;
862 goto Cleanup;
863 }
864
865 // If this is a serial port, a temporary file handle may be opened.
866 if (pPort->PortType == PortType_PhysicalCOM)
867 {
868 if (_CreateNonspooledPort(pPort))
869 {
870 bOpenedPort = TRUE;
871 }
872 else if (GetLastError() != ERROR_SUCCESS)
873 {
874 dwErrorCode = GetLastError();
875 goto Cleanup;
876 }
877 }
878
879 // Pass the parameters to ReadFile.
880 if (!ReadFile(pPort->hFile, pBuffer, cbBuffer, pcbRead, NULL))
881 {
882 dwErrorCode = GetLastError();
883 ERR("ReadFile failed with error %lu!\n", dwErrorCode);
884 goto Cleanup;
885 }
886
887Cleanup:
888 if (bOpenedPort)
889 _ClosePortHandles(pPort);
890
891 SetLastError(dwErrorCode);
892 return (dwErrorCode == ERROR_SUCCESS);
893}
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
PVOID pBuffer

◆ LocalmonSetPortTimeOuts()

BOOL WINAPI LocalmonSetPortTimeOuts ( HANDLE  hPort,
LPCOMMTIMEOUTS  lpCTO,
DWORD  Reserved 
)

Definition at line 789 of file ports.c.

790{
791 BOOL bOpenedPort = FALSE;
792 DWORD dwErrorCode;
793 PLOCALMON_PORT pPort = (PLOCALMON_PORT)hPort;
794
795 TRACE("LocalmonSetPortTimeOuts(%p, %p, %lu)\n", hPort, lpCTO, Reserved);
796
797 // Sanity checks
798 if (!pPort || !lpCTO)
799 {
800 dwErrorCode = ERROR_INVALID_PARAMETER;
801 goto Cleanup;
802 }
803
804 // If this is a serial port, a temporary file handle may be opened.
805 if (pPort->PortType == PortType_PhysicalCOM)
806 {
807 if (_CreateNonspooledPort(pPort))
808 {
809 bOpenedPort = TRUE;
810 }
811 else if (GetLastError() != ERROR_SUCCESS)
812 {
813 dwErrorCode = GetLastError();
814 goto Cleanup;
815 }
816 }
817 else if (pPort->hFile == INVALID_HANDLE_VALUE)
818 {
819 // All other port types need to be opened already.
820 dwErrorCode = ERROR_INVALID_PARAMETER;
821 goto Cleanup;
822 }
823
824 // Finally pass the parameters to SetCommTimeouts.
825 if (!SetCommTimeouts(pPort->hFile, lpCTO))
826 {
827 dwErrorCode = GetLastError();
828 ERR("SetCommTimeouts failed with error %lu!\n", dwErrorCode);
829 goto Cleanup;
830 }
831
832 dwErrorCode = ERROR_SUCCESS;
833
834Cleanup:
835 if (bOpenedPort)
836 _ClosePortHandles(pPort);
837
838 SetLastError(dwErrorCode);
839 return (dwErrorCode == ERROR_SUCCESS);
840}
BOOL WINAPI SetCommTimeouts(HANDLE hComm, LPCOMMTIMEOUTS lptimeouts)
Definition: comm.c:1062
_Reserved_ PVOID Reserved
Definition: winddi.h:3974

◆ LocalmonShutdown()

void WINAPI LocalmonShutdown ( HANDLE  hMonitor)

Definition at line 112 of file main.c.

113{
114 PLOCALMON_HANDLE pLocalmon;
115 PLOCALMON_PORT pPort;
116 PLOCALMON_XCV pXcv;
118
119 TRACE("LocalmonShutdown(%p)\n", hMonitor);
120
121 pLocalmon = (PLOCALMON_HANDLE)hMonitor;
122
123 if ( pLocalmon->Sig != SIGLCMMON )
124 {
125 ERR("LocalmonShutdown : Invalid Monitor Handle\n",hMonitor);
126 return;
127 }
128
129 // Close all virtual file ports.
130 if (!IsListEmpty(&pLocalmon->FilePorts))
131 {
132 for (pEntry = pLocalmon->FilePorts.Flink; pEntry != &pLocalmon->FilePorts; pEntry = pEntry->Flink)
133 {
134 pPort = CONTAINING_RECORD(&pLocalmon->FilePorts.Flink, LOCALMON_PORT, Entry);
136 }
137 }
138
139 // Do the same for the open Xcv ports.
140 if (!IsListEmpty(&pLocalmon->XcvHandles))
141 {
142 for (pEntry = pLocalmon->XcvHandles.Flink; pEntry != &pLocalmon->XcvHandles; pEntry = pEntry->Flink)
143 {
146 }
147 }
148
149 // Now close all registry ports, remove them from the list and free their memory.
150 if (!IsListEmpty(&pLocalmon->RegistryPorts))
151 {
152 for (pEntry = pLocalmon->RegistryPorts.Flink; pEntry != &pLocalmon->RegistryPorts; pEntry = pEntry->Flink)
153 {
155 if ( LocalmonClosePort((HANDLE)pPort) ) continue;
156 RemoveEntryList(&pPort->Entry);
157 DllFreeSplMem(pPort);
158 }
159 }
160
161 // Finally clean the LOCALMON_HANDLE structure itself.
162 DeleteCriticalSection(&pLocalmon->Section);
163 DllFreeSplMem(pLocalmon);
164}
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
LIST_ENTRY XcvHandles
Definition: precomp.h:44
BOOL WINAPI LocalmonClosePort(HANDLE hPort)
Definition: ports.c:456
BOOL WINAPI LocalmonXcvClosePort(HANDLE hXcv)
Definition: xcv.c:502
#define SIGLCMMON
Definition: precomp.h:30
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

◆ LocalmonStartDocPort()

BOOL WINAPI LocalmonStartDocPort ( HANDLE  hPort,
PWSTR  pPrinterName,
DWORD  JobId,
DWORD  Level,
PBYTE  pDocInfo 
)

Definition at line 896 of file ports.c.

897{
898 DWORD dwErrorCode;
899 PDOC_INFO_1W pDocInfo1 = (PDOC_INFO_1W)pDocInfo; // DOC_INFO_1W is the least common denominator for both DOC_INFO levels.
900 PLOCALMON_PORT pPort = (PLOCALMON_PORT)hPort;
901
902 TRACE("LocalmonStartDocPort(%p, %S, %lu, %lu, %p)\n", hPort, pPrinterName, JobId, Level, pDocInfo);
903
904 // Sanity checks
905 if (!pPort || !pPrinterName || (pPort->PortType == PortType_FILE && (!pDocInfo1 || !pDocInfo1->pOutputFile || !*pDocInfo1->pOutputFile)))
906 {
907 dwErrorCode = ERROR_INVALID_PARAMETER;
908 goto Cleanup;
909 }
910
911 if (Level > 2)
912 {
913 dwErrorCode = ERROR_INVALID_LEVEL;
914 goto Cleanup;
915 }
916
917 // Calling StartDocPort multiple times isn't considered a failure, but we don't need to do anything then.
918 if (pPort->bStartedDoc)
919 {
920 dwErrorCode = ERROR_SUCCESS;
921 goto Cleanup;
922 }
923
924 // Open a handle to the given printer for later reporting our progress using SetJobW.
925 if (!OpenPrinterW(pPrinterName, &pPort->hPrinter, NULL))
926 {
927 dwErrorCode = GetLastError();
928 ERR("OpenPrinterW failed with error %lu!\n", dwErrorCode);
929 goto Cleanup;
930 }
931
932 // We need our Job ID for SetJobW as well.
933 pPort->dwJobID = JobId;
934
935 // Check the port type.
936 if (pPort->PortType == PortType_PhysicalLPT)
937 {
938 // Update the NONSPOOLED mapping if the port mapping has changed since our OpenPort call.
940 {
941 dwErrorCode = GetLastError();
942 goto Cleanup;
943 }
944
945 // Update the transmission retry timeout as well.
947 }
948 else if(pPort->PortType == PortType_FILE)
949 {
950 // This is a FILE: port. Open the output file given in the Document Info.
952 if (pPort->hFile == INVALID_HANDLE_VALUE)
953 {
954 dwErrorCode = GetLastError();
955 goto Cleanup;
956 }
957 }
958 else
959 {
960 // This can be:
961 // - a physical COM port
962 // - a non-physical LPT port (e.g. with "net use LPT1 ...")
963 // - any other port (e.g. a file or a shared printer installed as a local port)
964 //
965 // For all these cases, we try to create a NONSPOOLED port per job.
966 // If _CreateNonspooledPort reports that no NONSPOOLED port is necessary, we can just open the port name.
967 if (!_CreateNonspooledPort(pPort))
968 {
970 {
972 if (pPort->hFile == INVALID_HANDLE_VALUE)
973 {
974 dwErrorCode = GetLastError();
975 goto Cleanup;
976 }
977 }
978 else
979 {
980 dwErrorCode = GetLastError();
981 goto Cleanup;
982 }
983 }
984 }
985
986 // We were successful!
987 dwErrorCode = ERROR_SUCCESS;
988 pPort->bStartedDoc = TRUE;
989
990Cleanup:
991 SetLastError(dwErrorCode);
992 return (dwErrorCode == ERROR_SUCCESS);
993}
#define FILE_SHARE_READ
Definition: compat.h:136
#define CREATE_ALWAYS
Definition: disk.h:72
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
LPWSTR pOutputFile
Definition: winspool.h:617
WINBOOL WINAPI OpenPrinterW(LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault)
Definition: printers.c:2653
struct _DOC_INFO_1W * PDOC_INFO_1W

◆ LocalmonWritePort()

BOOL WINAPI LocalmonWritePort ( HANDLE  hPort,
PBYTE  pBuffer,
DWORD  cbBuf,
PDWORD  pcbWritten 
)

Definition at line 996 of file ports.c.

997{
998 BOOL bOpenedPort = FALSE;
999 DWORD dwErrorCode;
1000 PLOCALMON_PORT pPort = (PLOCALMON_PORT)hPort;
1001
1002 TRACE("LocalmonWritePort(%p, %p, %lu, %p)\n", hPort, pBuffer, cbBuf, pcbWritten);
1003
1004 // Sanity checks
1005 if (!pPort || (cbBuf && !pBuffer) || !pcbWritten)
1006 {
1007 dwErrorCode = ERROR_INVALID_PARAMETER;
1008 goto Cleanup;
1009 }
1010
1011 // If this is a serial port, a temporary file handle may be opened.
1012 if (pPort->PortType == PortType_PhysicalCOM)
1013 {
1014 if (_CreateNonspooledPort(pPort))
1015 {
1016 bOpenedPort = TRUE;
1017 }
1018 else if (GetLastError() != ERROR_SUCCESS)
1019 {
1020 dwErrorCode = GetLastError();
1021 goto Cleanup;
1022 }
1023 }
1024 else if (pPort->hFile == INVALID_HANDLE_VALUE)
1025 {
1026 // All other port types need to be opened already.
1027 dwErrorCode = ERROR_INVALID_PARAMETER;
1028 goto Cleanup;
1029 }
1030
1031 // Pass the parameters to WriteFile.
1032 if (!WriteFile(pPort->hFile, pBuffer, cbBuf, pcbWritten, NULL))
1033 {
1034 dwErrorCode = GetLastError();
1035 ERR("WriteFile failed with error %lu!\n", dwErrorCode);
1036 goto Cleanup;
1037 }
1038
1039 // If something was written down, we consider that a success, otherwise it's a timeout.
1040 if (*pcbWritten)
1041 dwErrorCode = ERROR_SUCCESS;
1042 else
1043 dwErrorCode = ERROR_TIMEOUT;
1044
1045Cleanup:
1046 if (bOpenedPort)
1047 _ClosePortHandles(pPort);
1048
1049 SetLastError(dwErrorCode);
1050 return (dwErrorCode == ERROR_SUCCESS);
1051}
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define ERROR_TIMEOUT
Definition: winerror.h:941

◆ LocalmonXcvClosePort()

BOOL WINAPI LocalmonXcvClosePort ( HANDLE  hXcv)

Definition at line 502 of file xcv.c.

503{
505
506 TRACE("LocalmonXcvClosePort(%p)\n", hXcv);
507
508 // Sanity checks
509 if (!pXcv)
510 {
512 return FALSE;
513 }
514
515 // Remove it from the list and free the memory.
517 RemoveEntryList(&pXcv->Entry);
519 DllFreeSplMem(pXcv);
520
522 return TRUE;
523}
static HANDLE hXcv
Definition: localmon.c:73
PLOCALMON_HANDLE pLocalmon
Definition: precomp.h:81
LIST_ENTRY Entry
Definition: precomp.h:79
struct _LOCALMON_XCV * PLOCALMON_XCV

Referenced by LocalmonShutdown().

◆ LocalmonXcvDataPort()

DWORD WINAPI LocalmonXcvDataPort ( HANDLE  hXcv,
PCWSTR  pszDataName,
PBYTE  pInputData,
DWORD  cbInputData,
PBYTE  pOutputData,
DWORD  cbOutputData,
PDWORD  pcbOutputNeeded 
)

Definition at line 526 of file xcv.c.

527{
528 FIXME("LocalmonXcvDataPort(%p, %S, %p, %lu, %p, %lu, %p)\n", hXcv, pszDataName, pInputData, cbInputData, pOutputData, cbOutputData, pcbOutputNeeded);
529
530 // Sanity checks
531 if (!pszDataName)
533
534 // Call the appropriate handler for the requested data name.
535 if (wcscmp(pszDataName, L"AddPort") == 0)
536 return _HandleAddPort((PLOCALMON_XCV)hXcv, pInputData, pcbOutputNeeded);
537
538 if (wcscmp(pszDataName, L"ConfigureLPTPortCommandOK") == 0)
539 return _HandleConfigureLPTPortCommandOK((PLOCALMON_XCV)hXcv, pInputData, pcbOutputNeeded);
540
541 if (wcscmp(pszDataName, L"DeletePort") == 0)
542 return _HandleDeletePort((PLOCALMON_XCV)hXcv, pInputData, pcbOutputNeeded);
543
544 if (wcscmp(pszDataName, L"GetDefaultCommConfig") == 0)
545 return _HandleGetDefaultCommConfig(pInputData, pOutputData, cbOutputData, pcbOutputNeeded);
546
547 if (wcscmp(pszDataName, L"GetTransmissionRetryTimeout") == 0)
548 return _HandleGetTransmissionRetryTimeout(pOutputData, cbOutputData, pcbOutputNeeded);
549
550 if (wcscmp(pszDataName, L"MonitorUI") == 0)
551 return _HandleMonitorUI(pOutputData, cbOutputData, pcbOutputNeeded);
552
553 if (wcscmp(pszDataName, L"PortExists") == 0)
554 return _HandlePortExists(pInputData, pOutputData, cbOutputData, pcbOutputNeeded);
555
556 if (wcscmp(pszDataName, L"PortIsValid") == 0)
557 return _HandlePortIsValid(pInputData, pOutputData, cbOutputData, pcbOutputNeeded);
558
559 if (wcscmp(pszDataName, L"SetDefaultCommConfig") == 0)
560 return _HandleSetDefaultCommConfig((PLOCALMON_XCV)hXcv, pInputData, pcbOutputNeeded);
561
563}
static DWORD _HandleGetTransmissionRetryTimeout(PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:304
static DWORD _HandleDeletePort(PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:167
static DWORD _HandleSetDefaultCommConfig(PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:442
static DWORD _HandlePortIsValid(PBYTE pInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:403
static DWORD _HandleGetDefaultCommConfig(PBYTE pInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:266
static DWORD _HandlePortExists(PBYTE pInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:385
static DWORD _HandleConfigureLPTPortCommandOK(PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:105
static DWORD _HandleAddPort(PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:11
static DWORD _HandleMonitorUI(PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:342
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

◆ LocalmonXcvOpenPort()

BOOL WINAPI LocalmonXcvOpenPort ( HANDLE  hMonitor,
PCWSTR  pszObject,
ACCESS_MASK  GrantedAccess,
PHANDLE  phXcv 
)

Definition at line 566 of file xcv.c.

567{
568 DWORD cbObject = 0;
569 DWORD dwErrorCode;
570 PLOCALMON_HANDLE pLocalmon = (PLOCALMON_HANDLE)hMonitor;
571 PLOCALMON_XCV pXcv;
572
573 FIXME("LocalmonXcvOpenPort(%p, %S, %lu, %p)\n", hMonitor, pwszObject, GrantedAccess, phXcv);
574
575 // Sanity checks
576 if (!pLocalmon || !phXcv)
577 {
578 dwErrorCode = ERROR_INVALID_PARAMETER;
579 goto Cleanup;
580 }
581
582 if (pwszObject)
583 cbObject = (wcslen(pwszObject) + 1) * sizeof(WCHAR);
584
585 // Create a new LOCALMON_XCV structure and fill the relevant fields.
586 pXcv = DllAllocSplMem(sizeof(LOCALMON_XCV) + cbObject);
587 if (!pXcv)
588 {
589 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
590 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
591 goto Cleanup;
592 }
593
594 pXcv->pLocalmon = pLocalmon;
596
597 if (cbObject)
598 {
599 pXcv->pwszObject = (PWSTR)((PBYTE)pXcv + sizeof(LOCALMON_XCV));
600 CopyMemory(pXcv->pwszObject, pwszObject, cbObject);
601 }
602
603 InsertTailList(&pLocalmon->XcvHandles, &pXcv->Entry);
604
605 // Return it as the Xcv handle.
606 *phXcv = (HANDLE)pXcv;
607 dwErrorCode = ERROR_SUCCESS;
608
609Cleanup:
610 SetLastError(dwErrorCode);
611 return (dwErrorCode == ERROR_SUCCESS);
612}
PWSTR pwszObject
Definition: precomp.h:82
ACCESS_MASK GrantedAccess
Definition: precomp.h:80
PVOID HANDLE
Definition: typedefs.h:73
struct _LOCALMON_XCV LOCALMON_XCV
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET _In_ PGENERIC_MAPPING _In_ KPROCESSOR_MODE _Out_ PACCESS_MASK GrantedAccess
Definition: sefuncs.h:20

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( localmon  )

Variable Documentation

◆ cbLocalMonitor

DWORD cbLocalMonitor
extern

Definition at line 11 of file main.c.

Referenced by _LoadResources(), and _LocalmonGetPortLevel2().

◆ cbLocalPort

DWORD cbLocalPort
extern

Definition at line 12 of file main.c.

Referenced by _LoadResources(), and _LocalmonGetPortLevel2().

◆ pwszLocalMonitor

PCWSTR pwszLocalMonitor
extern

Definition at line 13 of file main.c.

Referenced by _LoadResources(), and _LocalmonGetPortLevel2().

◆ pwszLocalPort

PCWSTR pwszLocalPort
extern

Definition at line 14 of file main.c.

Referenced by _LoadResources(), and _LocalmonGetPortLevel2().