Skip to content

Commit

Permalink
#812: move definitions to common location, add ctypes wrappers for cl…
Browse files Browse the repository at this point in the history
…ipboard functions

git-svn-id: https://xpra.org/svn/Xpra/trunk@22378 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 12, 2019
1 parent dd14410 commit 409d6fa
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 48 deletions.
67 changes: 67 additions & 0 deletions src/xpra/platform/win32/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ def GetMonitorInfo(hmonitor):
GetProductInfo.argtypes = [DWORD, DWORD, DWORD, DWORD, PDWORD]
GetProductInfo.restype = BOOL
GetStdHandle = WINFUNCTYPE(HANDLE, DWORD)(("GetStdHandle", kernel32))
HGLOBAL = HANDLE
GlobalLock = kernel32.GlobalLock
GlobalLock.restype = LPVOID
GlobalLock.argtypes = [HGLOBAL]
GlobalUnlock = kernel32.GlobalUnlock
GlobalUnlock.restype = BOOL
GlobalUnlock.argtypes = [HGLOBAL]


user32 = WinDLL("user32", use_last_error=True)
RegisterClassExA = user32.RegisterClassExA
Expand Down Expand Up @@ -356,6 +364,27 @@ def GetMonitorInfo(hmonitor):
AppendMenu = user32.AppendMenuW
AppendMenu.restype = BOOL
AppendMenu.argtypes = [HMENU, UINT, UINT, LPCWSTR]
OpenClipboard = user32.OpenClipboard
OpenClipboard.restype = BOOL
OpenClipboard.argtypes = [HWND]
CloseClipboard = user32.CloseClipboard
CloseClipboard.restype = BOOL
CloseClipboard.argtypes = []
EmptyClipboard = user32.EmptyClipboard
EmptyClipboard.restype = BOOL
EmptyClipboard.argtypes = []
SetClipboardData = user32.SetClipboardData
SetClipboardData.restype = HANDLE
SetClipboardData.argtypes = [UINT, HANDLE]
RegisterClipboardFormatA = user32.RegisterClipboardFormatA
RegisterClipboardFormatA.restype = UINT
RegisterClipboardFormatA.argtypes = [LPCSTR]
GetClipboardFormatNameA = user32.GetClipboardFormatNameA
GetClipboardFormatNameA.restype = int
GetClipboardFormatNameA.argtypes = [UINT, LPCTSTR, int]
RegisterClipboardFormatA = user32.RegisterClipboardFormatA
RegisterClipboardFormatA.restype = UINT
RegisterClipboardFormatA.argtypes = [LPCSTR]

gdi32 = WinDLL("gdi32", use_last_error=True)
CreateCompatibleDC = gdi32.CreateCompatibleDC
Expand Down Expand Up @@ -480,3 +509,41 @@ def __str__(self):

IID = GUID
REFIID = POINTER(IID)


ERROR_BROKEN_PIPE = 109
ERROR_PIPE_NOT_CONNECTED = 233
ERROR_MORE_DATA = 234
ERROR_BROKEN_PIPE = 109
ERROR_NO_DATA = 232
ERROR_HANDLE_EOF = 38
ERROR_IO_INCOMPLETE = 996
ERROR_IO_PENDING = 997
ERROR_MORE_DATA = 234
ERROR_CANCELLED = 1223
ERROR_ACCESS_DENIED = 5
ERROR_INVALID_HANDLE = 6
ERROR_OPERATION_ABORTED = 995
ERROR_INVALID_PARAMETER = 87
ERROR_SUCCESS = 0
ERROR_COUNTER_TIMEOUT = 1121
ERROR_PIPE_BUSY = 231

IO_ERROR_STR = {
ERROR_PIPE_NOT_CONNECTED : "PIPE_NOT_CONNECTED",
ERROR_MORE_DATA : "MORE_DATA",
ERROR_BROKEN_PIPE : "BROKEN_PIPE",
ERROR_NO_DATA : "NO_DATA",
ERROR_HANDLE_EOF : "HANDLE_EOF",
ERROR_IO_INCOMPLETE : "IO_INCOMPLETE",
ERROR_IO_PENDING : "IO_PENDING",
ERROR_MORE_DATA : "MORE_DATA",
ERROR_CANCELLED : "CANCELLED",
ERROR_ACCESS_DENIED : "ACCESS_DENIED",
ERROR_INVALID_HANDLE : "INVALID_HANDLE",
ERROR_OPERATION_ABORTED : "OPERATION_ABORTED",
ERROR_INVALID_PARAMETER : "INVALID_PARAMETER",
ERROR_SUCCESS : "SUCCESS",
ERROR_COUNTER_TIMEOUT : "COUNTER_TIMEOUT",
ERROR_PIPE_BUSY : "PIPE_BUSY",
}
37 changes: 0 additions & 37 deletions src/xpra/platform/win32/namedpipes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,6 @@
INFINITE = 65535
INVALID_HANDLE_VALUE = -1

ERROR_BROKEN_PIPE = 109
ERROR_PIPE_NOT_CONNECTED = 233
ERROR_MORE_DATA = 234
ERROR_BROKEN_PIPE = 109
ERROR_NO_DATA = 232
ERROR_HANDLE_EOF = 38
ERROR_IO_INCOMPLETE = 996
ERROR_IO_PENDING = 997
ERROR_MORE_DATA = 234
ERROR_CANCELLED = 1223
ERROR_ACCESS_DENIED = 5
ERROR_INVALID_HANDLE = 6
ERROR_OPERATION_ABORTED = 995
ERROR_INVALID_PARAMETER = 87
ERROR_SUCCESS = 0
ERROR_COUNTER_TIMEOUT = 1121
ERROR_PIPE_BUSY = 231

ERROR_STR = {
ERROR_PIPE_NOT_CONNECTED : "PIPE_NOT_CONNECTED",
ERROR_MORE_DATA : "MORE_DATA",
ERROR_BROKEN_PIPE : "BROKEN_PIPE",
ERROR_NO_DATA : "NO_DATA",
ERROR_HANDLE_EOF : "HANDLE_EOF",
ERROR_IO_INCOMPLETE : "IO_INCOMPLETE",
ERROR_IO_PENDING : "IO_PENDING",
ERROR_MORE_DATA : "MORE_DATA",
ERROR_CANCELLED : "CANCELLED",
ERROR_ACCESS_DENIED : "ACCESS_DENIED",
ERROR_INVALID_HANDLE : "INVALID_HANDLE",
ERROR_OPERATION_ABORTED : "OPERATION_ABORTED",
ERROR_INVALID_PARAMETER : "INVALID_PARAMETER",
ERROR_SUCCESS : "SUCCESS",
ERROR_COUNTER_TIMEOUT : "COUNTER_TIMEOUT",
ERROR_PIPE_BUSY : "PIPE_BUSY",
}


class _inner_struct(Structure):
_fields_ = [
Expand Down
17 changes: 10 additions & 7 deletions src/xpra/platform/win32/namedpipes/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
from xpra.os_util import strtobytes
from xpra.net.bytestreams import Connection
from xpra.net.common import ConnectionClosedException
from xpra.platform.win32.common import CloseHandle
from xpra.platform.win32.common import (
CloseHandle,
ERROR_PIPE_BUSY, ERROR_PIPE_NOT_CONNECTED,
IO_ERROR_STR, ERROR_BROKEN_PIPE, ERROR_IO_PENDING,
)
from xpra.platform.win32.namedpipes.common import (
OVERLAPPED, WAIT_STR, INVALID_HANDLE_VALUE,
ERROR_PIPE_BUSY, ERROR_PIPE_NOT_CONNECTED,
INFINITE, ERROR_STR, ERROR_BROKEN_PIPE, ERROR_IO_PENDING,
INFINITE,
)
from xpra.platform.win32.namedpipes.common import (
CreateEventA, CreateFileA,
Expand Down Expand Up @@ -97,7 +100,7 @@ def _pipe_read(self, buf):
if not r and self.pipe_handle:
e = GetLastError()
if e!=ERROR_IO_PENDING:
log("ReadFile: %s", ERROR_STR.get(e, e))
log("ReadFile: %s", IO_ERROR_STR.get(e, e))
r = WaitForSingleObject(self.read_event, INFINITE)
log("WaitForSingleObject(..)=%s, len=%s", WAIT_STR.get(r, r), read.value)
if r and self.pipe_handle:
Expand All @@ -106,7 +109,7 @@ def _pipe_read(self, buf):
if not GetOverlappedResult(self.pipe_handle, byref(self.read_overlapped), byref(read), False):
e = GetLastError()
if e!=ERROR_BROKEN_PIPE:
raise Exception("overlapped read failed: %s" % ERROR_STR.get(e, e))
raise Exception("overlapped read failed: %s" % IO_ERROR_STR.get(e, e))
if read.value==0:
data = None
else:
Expand All @@ -126,7 +129,7 @@ def _pipe_write(self, buf):
if not r and self.pipe_handle:
e = GetLastError()
if e!=ERROR_IO_PENDING:
log("WriteFile: %s", ERROR_STR.get(e, e))
log("WriteFile: %s", IO_ERROR_STR.get(e, e))
r = WaitForSingleObject(self.write_event, INFINITE)
log("WaitForSingleObject(..)=%s, len=%i", WAIT_STR.get(r, r), written.value)
if not self.pipe_handle:
Expand All @@ -137,7 +140,7 @@ def _pipe_write(self, buf):
if self.pipe_handle:
if not GetOverlappedResult(self.pipe_handle, byref(self.write_overlapped), byref(written), False):
e = GetLastError()
raise Exception("overlapped write failed: %s" % ERROR_STR.get(e, e))
raise Exception("overlapped write failed: %s" % IO_ERROR_STR.get(e, e))
log("pipe_write: %i bytes written", written.value)
if self.pipe_handle:
FlushFileBuffers(self.pipe_handle)
Expand Down
21 changes: 17 additions & 4 deletions src/xpra/platform/win32/namedpipes/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,23 @@
from xpra.util import envbool
from xpra.os_util import strtobytes
from xpra.platform.win32.common import CloseHandle
from xpra.platform.win32.namedpipes.common import OVERLAPPED, INFINITE, WAIT_STR, SECURITY_DESCRIPTOR, SECURITY_ATTRIBUTES, TOKEN_USER
from xpra.platform.win32.namedpipes.common import CreateEventA, CreateNamedPipeA, ConnectNamedPipe, WaitForSingleObject, GetLastError
from xpra.platform.win32.namedpipes.common import SetSecurityDescriptorDacl, InitializeSecurityDescriptor, GetCurrentProcess, OpenProcessToken, GetTokenInformation, SetSecurityDescriptorOwner
from xpra.platform.win32.constants import FILE_FLAG_OVERLAPPED, PIPE_ACCESS_DUPLEX, PIPE_READMODE_BYTE, PIPE_UNLIMITED_INSTANCES, PIPE_WAIT, PIPE_TYPE_BYTE, NMPWAIT_USE_DEFAULT_WAIT
from xpra.platform.win32.namedpipes.common import (
OVERLAPPED, INFINITE, WAIT_STR,
SECURITY_DESCRIPTOR, SECURITY_ATTRIBUTES, TOKEN_USER,
)
from xpra.platform.win32.namedpipes.common import (
CreateEventA, CreateNamedPipeA, ConnectNamedPipe,
WaitForSingleObject, GetLastError,
)
from xpra.platform.win32.namedpipes.common import (
SetSecurityDescriptorDacl, InitializeSecurityDescriptor,
GetCurrentProcess, OpenProcessToken, GetTokenInformation,
SetSecurityDescriptorOwner,
)
from xpra.platform.win32.constants import (
FILE_FLAG_OVERLAPPED, PIPE_ACCESS_DUPLEX, PIPE_READMODE_BYTE,
PIPE_UNLIMITED_INSTANCES, PIPE_WAIT, PIPE_TYPE_BYTE, NMPWAIT_USE_DEFAULT_WAIT,
)
log = Logger("network", "named-pipe", "win32")

UNRESTRICTED = envbool("XPRA_NAMED_PIPE_UNRESTRICTED", False)
Expand Down

0 comments on commit 409d6fa

Please sign in to comment.