1 /*
2  * PROJECT:     ReactOS Local Port Monitor
3  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE:     Precompiled Header for all source files
5  * COPYRIGHT:   Copyright 2015 Colin Finck (colin@reactos.org)
6  */
7 
8 #ifndef _PRECOMP_H
9 #define _PRECOMP_H
10 
11 #define WIN32_NO_STATUS
12 #include <stdlib.h>
13 
14 #include <windef.h>
15 #include <winbase.h>
16 #include <wingdi.h>
17 #include <winreg.h>
18 #include <winspool.h>
19 #include <winsplp.h>
20 #include <winuser.h>
21 #include <ndk/rtlfuncs.h>
22 
23 #include <spoolss.h>
24 
25 #include <wine/debug.h>
26 WINE_DEFAULT_DEBUG_CHANNEL(localmon);
27 
28 #include "resource.h"
29 
30 #define SIGLCMMON  'FrCN'
31 #define SIGLCMPORT 'FrHK'
32 
33 // Structures
34 /**
35  * Describes the monitor handle returned by InitializePrintMonitor2.
36  * Manages all available ports in this instance.
37  */
38 typedef struct _LOCALMON_HANDLE
39 {
40     CRITICAL_SECTION Section;       /** Critical Section for modifying or reading the ports. */
41     DWORD Sig;
42     LIST_ENTRY FilePorts;           /** Ports created when a document is printed on FILE: and the user entered a file name. */
43     LIST_ENTRY RegistryPorts;       /** Valid ports loaded from the local registry. */
44     LIST_ENTRY XcvHandles;          /** Xcv handles created with LocalmonXcvOpenPort. */
45 }
46 LOCALMON_HANDLE, *PLOCALMON_HANDLE;
47 
48 /**
49  * Describes the port handle returned by LocalmonOpenPort.
50  * Manages a legacy port (COM/LPT) or virtual FILE: port for printing as well as its associated printer and job.
51  */
52 typedef struct _LOCALMON_PORT
53 {
54     LIST_ENTRY Entry;
55     PWSTR pwszPortName;             /** The name of this port including the trailing colon. Empty for virtual file ports. */
56     PLOCALMON_HANDLE pLocalmon;     /** Pointer to the parent LOCALMON_HANDLE structure. */
57     DWORD Sig;
58     enum {
59         PortType_Other = 0,         /** Any port that doesn't belong into the other categories (default). */
60         PortType_FILE,              /** A port created when a document is printed on FILE: and the user entered a file name. */
61         PortType_PhysicalCOM,       /** A physical serial port (COM) */
62         PortType_PhysicalLPT        /** A physical parallel port (LPT) */
63     }
64     PortType;
65     BOOL bStartedDoc;               /** Whether a document has been started with StartDocPort. */
66     DWORD dwJobID;                  /** ID of the printing job we are processing (for later reporting progress using SetJobW). */
67     HANDLE hFile;                   /** Handle to the opened port or INVALID_HANDLE_VALUE if it isn't currently opened. */
68     HANDLE hPrinter;                /** Handle to the printer for the job on this port (for using SetJobW). */
69     PWSTR pwszMapping;              /** The current mapping of the DOS Device corresponding to this port at the time _CreateNonspooledPort has been called. */
70 }
71 LOCALMON_PORT, *PLOCALMON_PORT;
72 
73 /**
74  * Describes the Xcv handle returned by LocalmonXcvOpenPort.
75  * Manages the required data for the Xcv* calls.
76  */
77 typedef struct _LOCALMON_XCV
78 {
79     LIST_ENTRY Entry;
80     ACCESS_MASK GrantedAccess;
81     PLOCALMON_HANDLE pLocalmon;
82     PWSTR pwszObject;
83 }
84 LOCALMON_XCV, *PLOCALMON_XCV;
85 
86 // main.c
87 extern DWORD cbLocalMonitor;
88 extern DWORD cbLocalPort;
89 extern PCWSTR pwszLocalMonitor;
90 extern PCWSTR pwszLocalPort;
91 void WINAPI LocalmonShutdown(HANDLE hMonitor);
92 
93 // ports.c
94 BOOL WINAPI LocalmonClosePort(HANDLE hPort);
95 BOOL WINAPI LocalmonEndDocPort(HANDLE hPort);
96 BOOL WINAPI LocalmonEnumPorts(HANDLE hMonitor, PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned);
97 BOOL WINAPI LocalmonGetPrinterDataFromPort(HANDLE hPort, DWORD ControlID, PWSTR pValueName, PWSTR lpInBuffer, DWORD cbInBuffer, PWSTR lpOutBuffer, DWORD cbOutBuffer, PDWORD lpcbReturned);
98 BOOL WINAPI LocalmonOpenPort(HANDLE hMonitor, PWSTR pName, PHANDLE pHandle);
99 BOOL WINAPI LocalmonReadPort(HANDLE hPort, PBYTE pBuffer, DWORD cbBuffer, PDWORD pcbRead);
100 BOOL WINAPI LocalmonSetPortTimeOuts(HANDLE hPort, LPCOMMTIMEOUTS lpCTO, DWORD Reserved);
101 BOOL WINAPI LocalmonStartDocPort(HANDLE hPort, PWSTR pPrinterName, DWORD JobId, DWORD Level, PBYTE pDocInfo);
102 BOOL WINAPI LocalmonWritePort(HANDLE hPort, PBYTE pBuffer, DWORD cbBuf, PDWORD pcbWritten);
103 BOOL WINAPI LocalmonAddPort( HANDLE hMonitor, LPWSTR pName, HWND hWnd, LPWSTR pMonitorName );
104 BOOL WINAPI LocalmonAddPortEx( HANDLE hMonitor, LPWSTR pName, DWORD Level, LPBYTE lpBuffer, LPWSTR lpMonitorName );
105 BOOL WINAPI LocalmonConfigurePort( HANDLE hMonitor, LPWSTR pName, HWND hWnd, LPWSTR pPortName );
106 BOOL WINAPI LocalmonDeletePort( HANDLE hMonitor, LPWSTR pName, HWND hWnd, LPWSTR pPortName );
107 
108 // tools.c
109 BOOL DoesPortExist(PCWSTR pwszPortName);
110 DWORD GetLPTTransmissionRetryTimeout(VOID);
111 DWORD GetPortNameWithoutColon(PCWSTR pwszPortName, PWSTR* ppwszPortNameWithoutColon);
112 DWORD GetTypeFromName(LPCWSTR name);
113 
114 // xcv.c
115 BOOL WINAPI LocalmonXcvClosePort(HANDLE hXcv);
116 DWORD WINAPI LocalmonXcvDataPort(HANDLE hXcv, PCWSTR pszDataName, PBYTE pInputData, DWORD cbInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded);
117 BOOL WINAPI LocalmonXcvOpenPort(HANDLE hMonitor, PCWSTR pszObject, ACCESS_MASK GrantedAccess, PHANDLE phXcv);
118 
119 #endif
120