Module: wine Branch: master Commit: bdd561cfa352ce18197a2d9018d7d6819db485fd URL: https://gitlab.winehq.org/wine/wine/-/commit/bdd561cfa352ce18197a2d9018d7d68...
Author: Piotr Caban piotr@codeweavers.com Date: Sun Nov 27 14:36:12 2022 +0100
localspl: Add FILE: port monitor implementation.
---
dlls/localspl/localmon.c | 111 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 83 insertions(+), 28 deletions(-)
diff --git a/dlls/localspl/localmon.c b/dlls/localspl/localmon.c index 381b36dd2e2..a982d359058 100644 --- a/dlls/localspl/localmon.c +++ b/dlls/localspl/localmon.c @@ -65,6 +65,7 @@ static CRITICAL_SECTION xcv_handles_cs = { &xcv_handles_cs_debug, -1, 0, 0, 0, 0 typedef struct { struct list entry; DWORD type; + HANDLE hfile; WCHAR nameW[1]; } port_t;
@@ -385,31 +386,6 @@ static BOOL WINAPI localmon_AddPortExW(LPWSTR pName, DWORD level, LPBYTE pBuffer return (res == ERROR_SUCCESS); }
-/***************************************************** - * localmon_ClosePort [exported through MONITOREX] - * - * Close a - * - * PARAMS - * hPort [i] The Handle to close - * - * RETURNS - * Success: TRUE - * Failure: FALSE - * - */ -static BOOL WINAPI localmon_ClosePort(HANDLE hPort) -{ - port_t * port = hPort; - - TRACE("(%p)\n", port); - EnterCriticalSection(&port_handles_cs); - list_remove(&port->entry); - LeaveCriticalSection(&port_handles_cs); - free(port); - return TRUE; -} - /***************************************************** * localmon_EnumPortsW [exported through MONITOREX] * @@ -501,6 +477,7 @@ static BOOL WINAPI localmon_OpenPortW(LPWSTR pName, PHANDLE phPort) if (!port) return FALSE;
port->type = type; + port->hfile = INVALID_HANDLE_VALUE; lstrcpyW(port->nameW, pName); *phPort = port;
@@ -512,6 +489,84 @@ static BOOL WINAPI localmon_OpenPortW(LPWSTR pName, PHANDLE phPort) return TRUE; }
+static BOOL WINAPI localmon_StartDocPort(HANDLE hport, WCHAR *printer_name, + DWORD job_id, DWORD level, BYTE *info) +{ + DOC_INFO_1W *doc_info = (DOC_INFO_1W *)info; + port_t *port = hport; + + TRACE("(%p %s %ld %ld %p)\n", hport, debugstr_w(printer_name), + job_id, level, doc_info); + + if (port->type != PORT_IS_FILE) + { + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; + } + + if (port->hfile != INVALID_HANDLE_VALUE) + return TRUE; + + if (!doc_info || !doc_info->pOutputFile) + { + FIXME("set error\n"); + return FALSE; + } + + port->hfile = CreateFileW(doc_info->pOutputFile, GENERIC_WRITE, + FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL); + return port->hfile != INVALID_HANDLE_VALUE; +} + +static BOOL WINAPI localmon_WritePort(HANDLE hport, BYTE *buf, DWORD size, + DWORD *written) +{ + port_t *port = hport; + + TRACE("(%p %p %lu %p)\n", hport, buf, size, written); + + return WriteFile(port->hfile, buf, size, written, NULL); +} + +static BOOL WINAPI localmon_EndDocPort(HANDLE hport) +{ + port_t *port = hport; + + TRACE("(%p)\n", hport); + + CloseHandle(port->hfile); + port->hfile = INVALID_HANDLE_VALUE; + return TRUE; +} + +/***************************************************** + * localmon_ClosePort [exported through MONITOREX] + * + * Close a Port + * + * PARAMS + * hport [i] The Handle to close + * + * RETURNS + * Success: TRUE + * Failure: FALSE + * + */ +static BOOL WINAPI localmon_ClosePort(HANDLE hport) +{ + port_t *port = hport; + + TRACE("(%p)\n", port); + + localmon_EndDocPort(hport); + + EnterCriticalSection(&port_handles_cs); + list_remove(&port->entry); + LeaveCriticalSection(&port_handles_cs); + free(port); + return TRUE; +} + /***************************************************** * localmon_XcvClosePort [exported through MONITOREX] * @@ -755,10 +810,10 @@ LPMONITOREX WINAPI InitializePrintMonitor(LPWSTR regroot) localmon_EnumPortsW, localmon_OpenPortW, NULL, /* localmon_OpenPortExW */ - NULL, /* localmon_StartDocPortW */ - NULL, /* localmon_WritePortW */ + localmon_StartDocPort, + localmon_WritePort, NULL, /* localmon_ReadPortW */ - NULL, /* localmon_EndDocPortW */ + localmon_EndDocPort, localmon_ClosePort, NULL, /* Use AddPortUI in localui.dll */ localmon_AddPortExW,