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 // Structures
31 /**
32  * Describes the monitor handle returned by InitializePrintMonitor2.
33  * Manages all available ports in this instance.
34  */
35 typedef struct _LOCALMON_HANDLE
36 {
37     CRITICAL_SECTION Section;       /** Critical Section for modifying or reading the ports. */
38     LIST_ENTRY FilePorts;           /** Ports created when a document is printed on FILE: and the user entered a file name. */
39     LIST_ENTRY RegistryPorts;       /** Valid ports loaded from the local registry. */
40     LIST_ENTRY XcvHandles;          /** Xcv handles created with LocalmonXcvOpenPort. */
41 }
42 LOCALMON_HANDLE, *PLOCALMON_HANDLE;
43 
44 /**
45  * Describes the port handle returned by LocalmonOpenPort.
46  * Manages a legacy port (COM/LPT) or virtual FILE: port for printing as well as its associated printer and job.
47  */
48 typedef struct _LOCALMON_PORT
49 {
50     LIST_ENTRY Entry;
51     enum {
52         PortType_Other = 0,         /** Any port that doesn't belong into the other categories (default). */
53         PortType_FILE,              /** A port created when a document is printed on FILE: and the user entered a file name. */
54         PortType_PhysicalCOM,       /** A physical serial port (COM) */
55         PortType_PhysicalLPT        /** A physical parallel port (LPT) */
56     }
57     PortType;
58     BOOL bStartedDoc;               /** Whether a document has been started with StartDocPort. */
59     DWORD dwJobID;                  /** ID of the printing job we are processing (for later reporting progress using SetJobW). */
60     HANDLE hFile;                   /** Handle to the opened port or INVALID_HANDLE_VALUE if it isn't currently opened. */
61     HANDLE hPrinter;                /** Handle to the printer for the job on this port (for using SetJobW). */
62     PLOCALMON_HANDLE pLocalmon;     /** Pointer to the parent LOCALMON_HANDLE structure. */
63     PWSTR pwszMapping;              /** The current mapping of the DOS Device corresponding to this port at the time _CreateNonspooledPort has been called. */
64     PWSTR pwszPortName;             /** The name of this port including the trailing colon. Empty for virtual file ports. */
65 }
66 LOCALMON_PORT, *PLOCALMON_PORT;
67 
68 /**
69  * Describes the Xcv handle returned by LocalmonXcvOpenPort.
70  * Manages the required data for the Xcv* calls.
71  */
72 typedef struct _LOCALMON_XCV
73 {
74     LIST_ENTRY Entry;
75     ACCESS_MASK GrantedAccess;
76     PLOCALMON_HANDLE pLocalmon;
77     PWSTR pwszObject;
78 }
79 LOCALMON_XCV, *PLOCALMON_XCV;
80 
81 // main.c
82 extern DWORD cbLocalMonitor;
83 extern DWORD cbLocalPort;
84 extern PCWSTR pwszLocalMonitor;
85 extern PCWSTR pwszLocalPort;
86 void WINAPI LocalmonShutdown(HANDLE hMonitor);
87 
88 // ports.c
89 BOOL WINAPI LocalmonClosePort(HANDLE hPort);
90 BOOL WINAPI LocalmonEndDocPort(HANDLE hPort);
91 BOOL WINAPI LocalmonEnumPorts(HANDLE hMonitor, PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned);
92 BOOL WINAPI LocalmonGetPrinterDataFromPort(HANDLE hPort, DWORD ControlID, PWSTR pValueName, PWSTR lpInBuffer, DWORD cbInBuffer, PWSTR lpOutBuffer, DWORD cbOutBuffer, PDWORD lpcbReturned);
93 BOOL WINAPI LocalmonOpenPort(HANDLE hMonitor, PWSTR pName, PHANDLE pHandle);
94 BOOL WINAPI LocalmonReadPort(HANDLE hPort, PBYTE pBuffer, DWORD cbBuffer, PDWORD pcbRead);
95 BOOL WINAPI LocalmonSetPortTimeOuts(HANDLE hPort, LPCOMMTIMEOUTS lpCTO, DWORD Reserved);
96 BOOL WINAPI LocalmonStartDocPort(HANDLE hPort, PWSTR pPrinterName, DWORD JobId, DWORD Level, PBYTE pDocInfo);
97 BOOL WINAPI LocalmonWritePort(HANDLE hPort, PBYTE pBuffer, DWORD cbBuf, PDWORD pcbWritten);
98 
99 // tools.c
100 BOOL DoesPortExist(PCWSTR pwszPortName);
101 DWORD GetLPTTransmissionRetryTimeout(VOID);
102 DWORD GetPortNameWithoutColon(PCWSTR pwszPortName, PWSTR* ppwszPortNameWithoutColon);
103 
104 // xcv.c
105 BOOL WINAPI LocalmonXcvClosePort(HANDLE hXcv);
106 DWORD WINAPI LocalmonXcvDataPort(HANDLE hXcv, PCWSTR pszDataName, PBYTE pInputData, DWORD cbInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded);
107 BOOL WINAPI LocalmonXcvOpenPort(HANDLE hMonitor, PCWSTR pszObject, ACCESS_MASK GrantedAccess, PHANDLE phXcv);
108 
109 #endif
110