localspl: [1/2] Implement OpenPort and ClosePort
Detlef Riekenberg
wine.dev at web.de
Mon Sep 10 08:09:56 CDT 2007
Changelog:
localspl: Implement OpenPort and ClosePort
Native localspl creates the handles for COM* and LPT*
in DLLMain and return always the same handle in OpenPort,
but there is no need for this in wine.
To simplify the code, my patch create always a new handle.
--
By by ... Detlef
-------------- next part --------------
>From 1c243f491419d28445ba1ac91dfac4e3f051e143 Mon Sep 17 00:00:00 2001
From: Detlef Riekenberg <wine.dev at web.de>
Date: Mon, 10 Sep 2007 15:02:58 +0200
Subject: [PATCH] localspl: Implement OpenPort and ClosePort
---
dlls/localspl/localmon.c | 130 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 128 insertions(+), 2 deletions(-)
diff --git a/dlls/localspl/localmon.c b/dlls/localspl/localmon.c
index aaf78a5..ce4d58e 100644
--- a/dlls/localspl/localmon.c
+++ b/dlls/localspl/localmon.c
@@ -42,6 +42,16 @@ WINE_DEFAULT_DEBUG_CHANNEL(localspl);
/*****************************************************/
+static CRITICAL_SECTION port_handles_cs;
+static CRITICAL_SECTION_DEBUG port_handles_cs_debug =
+{
+ 0, 0, &port_handles_cs,
+ { &port_handles_cs_debug.ProcessLocksList, &port_handles_cs_debug.ProcessLocksList },
+ 0, 0, { (DWORD_PTR)(__FILE__ ": port_handles_cs") }
+};
+static CRITICAL_SECTION port_handles_cs = { &port_handles_cs_debug, -1, 0, 0, 0, 0 };
+
+
static CRITICAL_SECTION xcv_handles_cs;
static CRITICAL_SECTION_DEBUG xcv_handles_cs_debug =
{
@@ -55,10 +65,17 @@ static CRITICAL_SECTION xcv_handles_cs =
typedef struct {
struct list entry;
+ DWORD type;
+ WCHAR nameW[1];
+} port_t;
+
+typedef struct {
+ struct list entry;
ACCESS_MASK GrantedAccess;
WCHAR nameW[1];
} xcv_t;
+static struct list port_handles = LIST_INIT( port_handles );
static struct list xcv_handles = LIST_INIT( xcv_handles );
/* ############################### */
@@ -299,6 +316,45 @@ static DWORD get_type_from_name(LPCWSTR
return PORT_IS_UNKNOWN;
}
+/*****************************************************
+ * get_type_from_local_name (internal)
+ *
+ */
+
+static DWORD get_type_from_local_name(LPCWSTR nameW)
+{
+ LPPORT_INFO_1W pi;
+ LPWSTR myname = NULL;
+ DWORD needed = 0;
+ DWORD numentries = 0;
+ DWORD id = 0;
+
+ TRACE("(%s)\n", debugstr_w(myname));
+
+ needed = get_ports_from_reg(1, NULL, 0, &numentries);
+ pi = spl_alloc(needed);
+ if (pi)
+ needed = get_ports_from_reg(1, (LPBYTE) pi, needed, &numentries);
+
+ if (pi && needed && numentries > 0) {
+ /* we got a number of valid ports. */
+
+ while ((myname == NULL) && (id < numentries))
+ {
+ if (lstrcmpiW(nameW, pi[id].pName) == 0) {
+ TRACE("(%u) found %s\n", id, debugstr_w(pi[id].pName));
+ myname = pi[id].pName;
+ }
+ id++;
+ }
+ }
+
+ id = (myname) ? get_type_from_name(myname) : PORT_IS_UNKNOWN;
+
+ spl_free(pi);
+ return id;
+
+}
/******************************************************************************
* localmon_AddPortExW [exported through MONITOREX]
*
@@ -357,6 +413,31 @@ static BOOL WINAPI localmon_AddPortExW(L
}
/*****************************************************
+ * 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 = (port_t *) hPort;
+
+ TRACE("(%p)\n", port);
+ EnterCriticalSection(&port_handles_cs);
+ list_remove(&port->entry);
+ LeaveCriticalSection(&port_handles_cs);
+ spl_free(port);
+ return TRUE;
+}
+
+/*****************************************************
* localmon_EnumPortsW [exported through MONITOREX]
*
* Enumerate all local Ports
@@ -416,6 +497,51 @@ cleanup:
}
/*****************************************************
+ * localmon_OpenPort [exported through MONITOREX]
+ *
+ * Open a Data-Channel for a Port
+ *
+ * PARAMS
+ * pName [i] Name of selected Object
+ * phPort [o] The resulting Handle is stored here
+ *
+ * RETURNS
+ * Success: TRUE
+ * Failure: FALSE
+ *
+ */
+static BOOL WINAPI localmon_OpenPortW(LPWSTR pName, PHANDLE phPort)
+{
+ port_t * port;
+ DWORD len;
+ DWORD type;
+
+ TRACE("%s, %p)\n", debugstr_w(pName), phPort);
+
+ /* an empty name is invalid */
+ if (!pName[0]) return FALSE;
+
+ /* does the port exist? */
+ type = get_type_from_local_name(pName);
+ if (!type) return FALSE;
+
+ len = (lstrlenW(pName) + 1) * sizeof(WCHAR);
+ port = spl_alloc(sizeof(port_t) + len);
+ if (!port) return FALSE;
+
+ port->type = type;
+ memcpy(&port->nameW, pName, len);
+ *phPort = (HANDLE) port;
+
+ EnterCriticalSection(&port_handles_cs);
+ list_add_tail(&port_handles, &port->entry);
+ LeaveCriticalSection(&port_handles_cs);
+
+ TRACE("=> %p\n", port);
+ return TRUE;
+}
+
+/*****************************************************
* localmon_XcvClosePort [exported through MONITOREX]
*
* Close a Communication-Channel
@@ -658,13 +784,13 @@ LPMONITOREX WINAPI InitializePrintMonito
sizeof(MONITOREX) - sizeof(DWORD),
{
localmon_EnumPortsW,
- NULL, /* localmon_OpenPortW */
+ localmon_OpenPortW,
NULL, /* localmon_OpenPortExW */
NULL, /* localmon_StartDocPortW */
NULL, /* localmon_WritePortW */
NULL, /* localmon_ReadPortW */
NULL, /* localmon_EndDocPortW */
- NULL, /* localmon_ClosePortW */
+ localmon_ClosePort,
NULL, /* Use AddPortUI in localui.dll */
localmon_AddPortExW,
NULL, /* Use ConfigurePortUI in localui.dll */
--
1.4.1
More information about the wine-patches
mailing list