Kitxuuu commited on
Commit
4a85060
·
verified ·
1 Parent(s): 4cb290b

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. local-test-freerdp-delta-01/afc-freerdp/CMakeCPack.cmake +98 -0
  2. local-test-freerdp-delta-01/afc-freerdp/CMakeCPackOptions.cmake.in +10 -0
  3. local-test-freerdp-delta-01/afc-freerdp/CMakeLists.txt +600 -0
  4. local-test-freerdp-delta-01/afc-freerdp/ChangeLog +622 -0
  5. local-test-freerdp-delta-01/afc-freerdp/LICENSE +202 -0
  6. local-test-freerdp-delta-01/afc-freerdp/README.md +44 -0
  7. local-test-freerdp-delta-01/afc-freerdp/SECURITY.md +114 -0
  8. local-test-freerdp-delta-01/afc-freerdp/channels/CMakeLists.txt +285 -0
  9. local-test-freerdp-delta-01/afc-freerdp/client/CMakeLists.txt +126 -0
  10. local-test-freerdp-delta-01/afc-freerdp/client/FreeRDP-ClientConfig.cmake.in +16 -0
  11. local-test-freerdp-delta-01/afc-freerdp/client/SDL/CMakeLists.txt +104 -0
  12. local-test-freerdp-delta-01/afc-freerdp/client/Sample/CMakeLists.txt +48 -0
  13. local-test-freerdp-delta-01/afc-freerdp/client/Sample/ModuleOptions.cmake +3 -0
  14. local-test-freerdp-delta-01/afc-freerdp/client/Sample/tf_channels.c +73 -0
  15. local-test-freerdp-delta-01/afc-freerdp/client/Sample/tf_channels.h +33 -0
  16. local-test-freerdp-delta-01/afc-freerdp/client/Sample/tf_freerdp.c +417 -0
  17. local-test-freerdp-delta-01/afc-freerdp/client/Sample/tf_freerdp.h +37 -0
  18. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/CMakeLists.txt +56 -0
  19. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_channels.c +79 -0
  20. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_channels.h +37 -0
  21. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_cliprdr.c +1018 -0
  22. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_cliprdr.h +36 -0
  23. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_disp.c +458 -0
  24. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_disp.h +38 -0
  25. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_input.c +455 -0
  26. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_input.h +45 -0
  27. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_pointer.c +167 -0
  28. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_pointer.h +28 -0
  29. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlfreerdp.1.in +38 -0
  30. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlfreerdp.c +815 -0
  31. local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlfreerdp.h +61 -0
  32. local-test-freerdp-delta-01/afc-freerdp/client/Windows/ModuleOptions.cmake +3 -0
  33. local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_channels.h +36 -0
  34. local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_client.c +1490 -0
  35. local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_client.h +158 -0
  36. local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_cliprdr.c +2549 -0
  37. local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_cliprdr.h +27 -0
  38. local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_floatbar.c +730 -0
  39. local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_floatbar.h +33 -0
  40. local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_gdi.c +848 -0
  41. local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_rail.c +994 -0
  42. local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_rail.h +33 -0
  43. local-test-freerdp-delta-01/afc-freerdp/client/freerdp-client.pc.in +15 -0
  44. local-test-freerdp-delta-01/afc-freerdp/client/iOS/AppDelegate.h +24 -0
  45. local-test-freerdp-delta-01/afc-freerdp/client/iOS/AppDelegate.m +127 -0
  46. local-test-freerdp-delta-01/afc-freerdp/client/iOS/CMakeLists.txt +160 -0
  47. local-test-freerdp-delta-01/afc-freerdp/client/iOS/Defaults.plist +92 -0
  48. local-test-freerdp-delta-01/afc-freerdp/client/iOS/ModuleOptions.cmake +3 -0
  49. local-test-freerdp-delta-01/afc-freerdp/client/iOS/iFreeRDP-Prefix.pch +23 -0
  50. local-test-freerdp-delta-01/afc-freerdp/client/iOS/iFreeRDP.plist +53 -0
local-test-freerdp-delta-01/afc-freerdp/CMakeCPack.cmake ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generate .txt license file for CPack (PackageMaker requires a file extension)
2
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/LICENSE ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt @ONLY)
3
+
4
+ # Workaround to remove c++ compiler macros and defines for Eclipse.
5
+ # If c++ macros/defines are set __cplusplus is also set which causes
6
+ # problems when compiling freerdp/jni. To prevent this problem we set the macros to "".
7
+
8
+ if(ANDROID AND CMAKE_EXTRA_GENERATOR STREQUAL "Eclipse CDT4")
9
+ set(CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_DEFINED_MACROS "")
10
+ message(STATUS "Disabled CXX system defines for eclipse (workaround).")
11
+ endif()
12
+
13
+ set(CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;/\\\\.gitignore;/CMakeCache.txt")
14
+
15
+ if(NOT WIN32)
16
+ if(APPLE AND (NOT IOS))
17
+
18
+ if(WITH_SERVER)
19
+ set(CPACK_PACKAGE_EXECUTABLES ${CPACK_PACKAGE_EXECUTABLES} "mfreerdp-server")
20
+ endif()
21
+ endif()
22
+
23
+ if(WITH_X11)
24
+ set(CPACK_PACKAGE_EXECUTABLES "xfreerdp")
25
+
26
+ if(WITH_SERVER)
27
+ set(CPACK_PACKAGE_EXECUTABLES ${CPACK_PACKAGE_EXECUTABLES} "xfreerdp-server")
28
+ endif()
29
+ endif()
30
+ endif()
31
+
32
+ set(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
33
+ set(CPACK_TOPLEVEL_TAG "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
34
+
35
+ string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_PROJECT_NAME_lower)
36
+ set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME_lower}-${FREERDP_VERSION_FULL}-${CPACK_SYSTEM_NAME}")
37
+ set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME_lower}-${FREERDP_VERSION_FULL}-${CPACK_SYSTEM_NAME}")
38
+
39
+ set(CPACK_PACKAGE_NAME "FreeRDP")
40
+ set(CPACK_PACKAGE_VENDOR "FreeRDP")
41
+ set(CPACK_PACKAGE_VERSION ${FREERDP_VERSION_FULL})
42
+ set(CPACK_PACKAGE_VERSION_MAJOR ${FREERDP_VERSION_MAJOR})
43
+ set(CPACK_PACKAGE_VERSION_MINOR ${FREERDP_VERSION_MINOR})
44
+ set(CPACK_PACKAGE_VERSION_PATCH ${FREERDP_VERSION_REVISION})
45
+ set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "FreeRDP: A Remote Desktop Protocol Implementation")
46
+
47
+ set(CPACK_PACKAGE_CONTACT "Marc-Andre Moreau")
48
+ set(CPACK_DEBIAN_PACKAGE_MAINTAINER "[email protected]")
49
+ set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
50
+
51
+ set(CPACK_PACKAGE_INSTALL_DIRECTORY "FreeRDP")
52
+ set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt")
53
+ set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt")
54
+
55
+ set(CPACK_NSIS_MODIFY_PATH ON)
56
+ set(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/resources\\\\FreeRDP_Install.bmp")
57
+ set(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/resources\\\\FreeRDP_Icon_96px.ico")
58
+ set(CPACK_NSIS_MUI_UNICON "${PROJECT_SOURCE_DIR}/resource\\\\FreeRDP_Icon_96px.ico")
59
+
60
+ set(CPACK_COMPONENTS_ALL client server libraries headers symbols tools)
61
+
62
+ if(MSVC)
63
+ string(FIND ${CMAKE_MSVC_RUNTIME_LIBRARY} "DLL" IS_SHARED)
64
+
65
+ if(NOT IS_SHARED STREQUAL "-1")
66
+ set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
67
+ include(InstallRequiredSystemLibraries)
68
+
69
+ install(PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries)
70
+ endif()
71
+ endif()
72
+
73
+ set(CPACK_COMPONENT_CLIENT_DISPLAY_NAME "Client")
74
+ set(CPACK_COMPONENT_CLIENT_GROUP "Applications")
75
+
76
+ set(CPACK_COMPONENT_SERVER_DISPLAY_NAME "Server")
77
+ set(CPACK_COMPONENT_SERVER_GROUP "Applications")
78
+
79
+ set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
80
+ set(CPACK_COMPONENT_LIBRARIES_GROUP "Runtime")
81
+
82
+ set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "Headers")
83
+ set(CPACK_COMPONENT_HEADERS_GROUP "Development")
84
+
85
+ set(CPACK_COMPONENT_SYMBOLS_DISPLAY_NAME "Symbols")
86
+ set(CPACK_COMPONENT_SYMBOLS_GROUP "Development")
87
+
88
+ set(CPACK_COMPONENT_TOOLS_DISPLAY_NAME "Tools")
89
+ set(CPACK_COMPONENT_TOOLS_GROUP "Applications")
90
+
91
+ set(CPACK_COMPONENT_GROUP_RUNTIME_DESCRIPTION "Runtime")
92
+ set(CPACK_COMPONENT_GROUP_APPLICATIONS_DESCRIPTION "Applications")
93
+ set(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION "Development")
94
+
95
+ configure_file("${PROJECT_SOURCE_DIR}/CMakeCPackOptions.cmake.in" "${PROJECT_BINARY_DIR}/CMakeCPackOptions.cmake" @ONLY)
96
+ set(CPACK_PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/CMakeCPackOptions.cmake")
97
+
98
+ include(CPack)
local-test-freerdp-delta-01/afc-freerdp/CMakeCPackOptions.cmake.in ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is configured at cmake time, and loaded at cpack time.
2
+ # To pass variables to cpack from cmake, they must be configured in this file.
3
+
4
+ if("${CPACK_GENERATOR}" STREQUAL "PackageMaker")
5
+ if(CMAKE_PACKAGE_QTGUI)
6
+ set(CPACK_PACKAGE_DEFAULT_LOCATION "/Applications")
7
+ else()
8
+ set(CPACK_PACKAGE_DEFAULT_LOCATION "/usr")
9
+ endif()
10
+ endif()
local-test-freerdp-delta-01/afc-freerdp/CMakeLists.txt ADDED
@@ -0,0 +1,600 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FreeRDP: A Remote Desktop Protocol Implementation
2
+ # FreeRDP cmake build script
3
+ #
4
+ # Copyright 2011 O.S. Systems Software Ltda.
5
+ # Copyright 2011 Otavio Salvador <[email protected]>
6
+ # Copyright 2011 Marc-Andre Moreau <[email protected]>
7
+ # Copyright 2012 HP Development Company, LLC
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+
21
+ cmake_minimum_required(VERSION 3.13)
22
+
23
+ if(POLICY CMP0091)
24
+ cmake_policy(SET CMP0091 NEW)
25
+ endif()
26
+ project(FreeRDP LANGUAGES C)
27
+
28
+ set(CMAKE_C_STANDARD 11)
29
+ set(CMAKE_C_STANDARD_REQUIRED ON)
30
+ set(CMAKE_C_EXTENSIONS ON)
31
+
32
+ add_custom_target(fuzzers COMMENT "Build fuzzers")
33
+
34
+ if(NOT DEFINED VENDOR)
35
+ set(VENDOR "FreeRDP" CACHE STRING "FreeRDP package vendor")
36
+ endif()
37
+
38
+ if(NOT DEFINED PRODUCT)
39
+ set(PRODUCT "FreeRDP" CACHE STRING "FreeRDP package name")
40
+ endif()
41
+
42
+ if(NOT DEFINED FREERDP_VENDOR)
43
+ set(FREERDP_VENDOR 1)
44
+ endif()
45
+
46
+ if(NOT WIN32 AND NOT ANDROID)
47
+ if(APPLE)
48
+ set(OPT_DEFAULT_VAL OFF)
49
+ else()
50
+ set(OPT_DEFAULT_VAL ON)
51
+ endif()
52
+ option(WITH_X11 "build X11 client/server" ${OPT_DEFAULT_VAL})
53
+ endif()
54
+
55
+ # Enable coverity related pragma definitions
56
+ if(COVERITY_BUILD)
57
+ add_compile_definitions(COVERITY_BUILD)
58
+ endif()
59
+
60
+ # Include our extra modules
61
+ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/)
62
+
63
+ # Check for cmake compatibility (enable/disable features)
64
+ include(CheckCmakeCompat)
65
+
66
+ # Include cmake modules
67
+ if(WITH_CLANG_FORMAT)
68
+ include(ClangFormat)
69
+ endif()
70
+
71
+ include(CompilerFlags)
72
+ include(CheckIncludeFiles)
73
+ include(CheckLibraryExists)
74
+ include(CheckSymbolExists)
75
+ include(CheckStructHasMember)
76
+ include(TestBigEndian)
77
+ include(CompilerDetect)
78
+
79
+ include(FindFeature)
80
+ include(ShowCMakeVars)
81
+ include(ConfigOptions)
82
+ include(FeatureSummary)
83
+ include(CheckCCompilerFlag)
84
+ include(CMakePackageConfigHelpers)
85
+ include(InstallFreeRDPMan)
86
+ include(GetGitRevisionDescription)
87
+ include(SetFreeRDPCMakeInstallDir)
88
+ include(Doxygen)
89
+
90
+ # Soname versioning
91
+ set(BUILD_NUMBER 0)
92
+ if($ENV{BUILD_NUMBER})
93
+ set(BUILD_NUMBER $ENV{BUILD_NUMBER})
94
+ endif()
95
+
96
+ set(VERSION_REGEX "^(.*)([0-9]+)\\.([0-9]+)\\.([0-9]+)-?(.*)")
97
+ set(RAW_VERSION_STRING "3.11.2-dev0")
98
+ if(EXISTS "${PROJECT_SOURCE_DIR}/.source_tag")
99
+ file(READ ${PROJECT_SOURCE_DIR}/.source_tag RAW_VERSION_STRING)
100
+ elseif(USE_VERSION_FROM_GIT_TAG)
101
+ git_get_exact_tag(_GIT_TAG --tags --always)
102
+ if(NOT ${_GIT_TAG} STREQUAL "n/a")
103
+ string(REGEX MATCH ${VERSION_REGEX} FOUND_TAG "${_GIT_TAG}")
104
+ if(FOUND_TAG)
105
+ set(RAW_VERSION_STRING ${_GIT_TAG})
106
+ endif()
107
+ endif()
108
+ endif()
109
+ string(STRIP ${RAW_VERSION_STRING} RAW_VERSION_STRING)
110
+
111
+ string(REGEX REPLACE "${VERSION_REGEX}" "\\2" FREERDP_VERSION_MAJOR "${RAW_VERSION_STRING}")
112
+ string(REGEX REPLACE "${VERSION_REGEX}" "\\3" FREERDP_VERSION_MINOR "${RAW_VERSION_STRING}")
113
+ string(REGEX REPLACE "${VERSION_REGEX}" "\\4" FREERDP_VERSION_REVISION "${RAW_VERSION_STRING}")
114
+ string(REGEX REPLACE "${VERSION_REGEX}" "\\5" FREERDP_VERSION_SUFFIX "${RAW_VERSION_STRING}")
115
+
116
+ set(FREERDP_API_VERSION "${FREERDP_VERSION_MAJOR}")
117
+ set(FREERDP_VERSION "${FREERDP_VERSION_MAJOR}.${FREERDP_VERSION_MINOR}.${FREERDP_VERSION_REVISION}")
118
+ if(FREERDP_VERSION_SUFFIX)
119
+ set(FREERDP_VERSION_FULL "${FREERDP_VERSION}-${FREERDP_VERSION_SUFFIX}")
120
+ else()
121
+ set(FREERDP_VERSION_FULL "${FREERDP_VERSION}")
122
+ endif()
123
+ message("FREERDP_VERSION=${FREERDP_VERSION_FULL}")
124
+
125
+ if(EXISTS "${PROJECT_SOURCE_DIR}/.source_version")
126
+ file(READ ${PROJECT_SOURCE_DIR}/.source_version GIT_REVISION)
127
+
128
+ string(STRIP ${GIT_REVISION} GIT_REVISION)
129
+ elseif(USE_VERSION_FROM_GIT_TAG)
130
+ git_get_exact_tag(GIT_REVISION --tags --always)
131
+
132
+ if(${GIT_REVISION} STREQUAL "n/a")
133
+ git_rev_parse(GIT_REVISION --short)
134
+ endif()
135
+ endif()
136
+
137
+ if(NOT GIT_REVISION)
138
+ set(GIT_REVISION ${FREERDP_VERSION})
139
+ endif()
140
+
141
+ message(STATUS "Git Revision ${GIT_REVISION}")
142
+
143
+ # MSVC compatibility with system headers
144
+ add_compile_definitions(NONAMELESSUNION)
145
+
146
+ # Make the detected version available as default version for all subprojects
147
+ set(FREERDP_DEFAULT_PROJECT_VERSION ${FREERDP_VERSION} CACHE STRING INTERNAL)
148
+
149
+ set(FREERDP_MAJOR_DIR "freerdp${FREERDP_VERSION_MAJOR}")
150
+ set(FREERDP_INCLUDE_DIR "include/${FREERDP_MAJOR_DIR}/")
151
+
152
+ option(WITH_SMARTCARD_EMULATE "Emulate smartcards instead of redirecting readers" ON)
153
+ if(WITH_SMARTCARD_EMULATE)
154
+ add_compile_definitions(WITH_SMARTCARD_EMULATE)
155
+ find_package(ZLIB REQUIRED)
156
+ endif()
157
+
158
+ option(WITH_FREERDP_DEPRECATED "Build FreeRDP deprecated symbols" OFF)
159
+ if(WITH_FREERDP_DEPRECATED)
160
+ add_compile_definitions(WITH_FREERDP_DEPRECATED)
161
+ endif()
162
+
163
+ option(WITH_FREERDP_DEPRECATED_COMMANDLINE "Build FreeRDP deprecated command line options" OFF)
164
+ if(WITH_FREERDP_DEPRECATED_COMMANDLINE)
165
+ add_compile_definitions(WITH_FREERDP_DEPRECATED_COMMANDLINE)
166
+ endif()
167
+
168
+ # Make paths absolute
169
+ if(CMAKE_INSTALL_PREFIX)
170
+ get_filename_component(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE)
171
+ endif()
172
+ if(FREERDP_EXTERNAL_PATH)
173
+ get_filename_component(FREERDP_EXTERNAL_PATH "${FREERDP_EXTERNAL_PATH}" ABSOLUTE)
174
+ endif()
175
+
176
+ # Allow to search the host machine for git/ccache
177
+ if(CMAKE_CROSSCOMPILING)
178
+ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
179
+ endif(CMAKE_CROSSCOMPILING)
180
+
181
+ find_program(CCACHE ccache)
182
+ if(CCACHE AND WITH_CCACHE)
183
+ if(NOT DEFINED CMAKE_C_COMPILER_LAUNCHER)
184
+ set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
185
+ endif(NOT DEFINED CMAKE_C_COMPILER_LAUNCHER)
186
+ endif(CCACHE AND WITH_CCACHE)
187
+
188
+ if(CMAKE_CROSSCOMPILING)
189
+ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
190
+ endif(CMAKE_CROSSCOMPILING)
191
+ # /Allow to search the host machine for git/ccache
192
+
193
+ # Turn on solution folders (2.8.4+)
194
+ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
195
+
196
+ option(CTEST_OUTPUT_ON_FAILURE ON "show verbose output on CTest failures")
197
+ if(BUILD_TESTING_INTERNAL)
198
+ set(EXPORT_ALL_SYMBOLS ON CACHE BOOL "testing default" FORCE)
199
+ add_compile_definitions(BUILD_TESTING_INTERNAL)
200
+ elseif(BUILD_TESTING)
201
+ set(EXPORT_ALL_SYMBOLS OFF CACHE BOOL "testing default" FORCE)
202
+ endif()
203
+
204
+ include(ExportAllSymbols)
205
+
206
+ set(THREAD_PREFER_PTHREAD_FLAG TRUE)
207
+
208
+ if(NOT IOS)
209
+ find_package(Threads REQUIRED)
210
+ endif()
211
+
212
+ if(WIN32)
213
+ add_compile_definitions(UNICODE _UNICODE)
214
+ add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
215
+ add_compile_definitions(WIN32_LEAN_AND_MEAN)
216
+ add_compile_definitions(_WINSOCK_DEPRECATED_NO_WARNINGS)
217
+
218
+ set(CMAKE_DL_LIBS "")
219
+ set(CMAKE_USE_RELATIVE_PATH ON)
220
+ string(TIMESTAMP RC_VERSION_YEAR "%Y")
221
+
222
+ if(NOT DEFINED CMAKE_WINDOWS_VERSION)
223
+ set(CMAKE_WINDOWS_VERSION "WIN7")
224
+ endif()
225
+
226
+ if(CMAKE_WINDOWS_VERSION STREQUAL "WINXP")
227
+ add_compile_definitions(WINVER=0x0501 _WIN32_WINNT=0x0501)
228
+ elseif(CMAKE_WINDOWS_VERSION STREQUAL "WIN7")
229
+ add_compile_definitions(WINVER=0x0601 _WIN32_WINNT=0x0601)
230
+ elseif(CMAKE_WINDOWS_VERSION STREQUAL "WIN8")
231
+ add_compile_definitions(WINVER=0x0602 _WIN32_WINNT=0x0602)
232
+ elseif(CMAKE_WINDOWS_VERSION STREQUAL "WIN10")
233
+ add_compile_definitions(WINVER=0x0A00 _WIN32_WINNT=0x0A00)
234
+ endif()
235
+
236
+ # Set product and vendor for dll and exe version information.
237
+ set(RC_VERSION_VENDOR ${VENDOR})
238
+ set(RC_VERSION_PRODUCT ${PRODUCT})
239
+ set(RC_VERSION_PATCH ${BUILD_NUMBER})
240
+ set(RC_VERSION_DESCRIPTION
241
+ "${FREERDP_VERSION_FULL} ${GIT_REVISION} ${CMAKE_WINDOWS_VERSION} ${CMAKE_SYSTEM_PROCESSOR}"
242
+ )
243
+
244
+ if(FREERDP_EXTERNAL_SSL_PATH)
245
+ set(OPENSSL_ROOT_DIR ${FREERDP_EXTERNAL_SSL_PATH})
246
+ endif()
247
+ endif()
248
+
249
+ add_compile_definitions(FREERDP_EXPORTS)
250
+
251
+ # Mac OS X
252
+ if(APPLE)
253
+ if(IOS)
254
+ if(NOT FREERDP_IOS_EXTERNAL_SSL_PATH)
255
+ message(
256
+ STATUS
257
+ "FREERDP_IOS_EXTERNAL_SSL_PATH not set! Required if openssl is not found in the iOS SDK (which usually isn't"
258
+ )
259
+ endif()
260
+ set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${FREERDP_IOS_EXTERNAL_SSL_PATH})
261
+ set_property(GLOBAL PROPERTY XCODE_ATTRIBUTE_SKIP_INSTALL YES)
262
+ endif(IOS)
263
+
264
+ # Temporarily disabled, causes the cmake script to be reexecuted, causing the compilation to fail.
265
+ # Workaround: specify the parameter in the command-line
266
+ # if(WITH_CLANG)
267
+ # set(CMAKE_C_COMPILER "clang")
268
+ # endif()
269
+
270
+ if(WITH_VERBOSE)
271
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -v")
272
+ endif()
273
+ endif(APPLE)
274
+
275
+ # Android
276
+ if(ANDROID)
277
+ set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ${ANDROID_LIBRARY_USE_LIB64_PATHS})
278
+
279
+ if(ANDROID_ABI STREQUAL arm64-v8a)
280
+ include(CheckCCompilerFlag)
281
+ check_c_compiler_flag("-mfloat-abi=softfp" ABI_SOFTFP_SUPPORTED)
282
+
283
+ if(ABI_SOFTFP_SUPPORTED)
284
+ # https://github.com/android/ndk/issues/910
285
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=softfp")
286
+ endif()
287
+ endif()
288
+
289
+ add_compile_definitions("$<$<CONFIG:Debug>:NDK_DEBUG=1>")
290
+
291
+ # NOTE: Manually add -gdwarf-3, as newer toolchains default to -gdwarf-4,
292
+ # which is not supported by the gdbserver binary shipped with
293
+ # the android NDK (tested with r9b)
294
+ add_compile_options("$<$<CONFIG:Debug>:-gdwarf-3>")
295
+ add_link_options(-llog)
296
+
297
+ # CMAKE_PREFIX_PATH detection is broken in most Android toolchain files
298
+ # Append it to CMAKE_FIND_ROOT_PATH and avoid potential duplicates
299
+ list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_PREFIX_PATH})
300
+ list(REMOVE_DUPLICATES CMAKE_FIND_ROOT_PATH)
301
+
302
+ if(NOT FREERDP_EXTERNAL_PATH)
303
+ if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/external/")
304
+ set(FREERDP_EXTERNAL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/external/")
305
+ else()
306
+ message(STATUS "FREERDP_EXTERNAL_PATH not set!")
307
+ endif()
308
+ endif()
309
+
310
+ list(APPEND CMAKE_INCLUDE_PATH ${FREERDP_EXTERNAL_PATH}/${ANDROID_ABI}/include)
311
+ list(APPEND CMAKE_LIBRARY_PATH ${FREERDP_EXTERNAL_PATH}/${ANDROID_ABI}/)
312
+ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
313
+ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
314
+
315
+ if(WITH_GPROF)
316
+ configure_file(
317
+ ${PROJECT_SOURCE_DIR}/scripts/gprof_generate.sh.in ${PROJECT_BINARY_DIR}/scripts/gprof_generate.sh @ONLY
318
+ )
319
+ endif(WITH_GPROF)
320
+ endif()
321
+
322
+ if(UNIX OR CYGWIN)
323
+ set(WAYLAND_FEATURE_TYPE "RECOMMENDED")
324
+ else()
325
+ set(WAYLAND_FEATURE_TYPE "DISABLED")
326
+ endif()
327
+
328
+ if(WITH_PCSC_WINPR)
329
+ find_package(PCSCWinPR)
330
+ endif()
331
+
332
+ set(WAYLAND_FEATURE_PURPOSE "Wayland")
333
+ set(WAYLAND_FEATURE_DESCRIPTION "Wayland client")
334
+
335
+ set(OPENSSL_FEATURE_TYPE "REQUIRED")
336
+ set(OPENSSL_FEATURE_PURPOSE "cryptography")
337
+ set(OPENSSL_FEATURE_DESCRIPTION "encryption, certificate validation, hashing functions")
338
+
339
+ set(MBEDTLS_FEATURE_TYPE "OPTIONAL")
340
+ set(MBEDTLS_FEATURE_PURPOSE "cryptography")
341
+ set(MBEDTLS_FEATURE_DESCRIPTION "encryption, certificate validation, hashing functions")
342
+
343
+ set(PCSC_FEATURE_TYPE "RECOMMENDED")
344
+ set(PCSC_FEATURE_PURPOSE "smart card")
345
+ set(PCSC_FEATURE_DESCRIPTION "smart card device redirection")
346
+
347
+ set(OPENH264_FEATURE_TYPE "OPTIONAL")
348
+ set(OPENH264_FEATURE_PURPOSE "codec")
349
+ set(OPENH264_FEATURE_DESCRIPTION "use OpenH264 library")
350
+
351
+ set(OPENCL_FEATURE_TYPE "OPTIONAL")
352
+ set(OPENCL_FEATURE_PURPOSE "codec")
353
+ set(OPENCL_FEATURE_DESCRIPTION "use OpenCL library")
354
+
355
+ set(GSM_FEATURE_TYPE "OPTIONAL")
356
+ set(GSM_FEATURE_PURPOSE "codec")
357
+ set(GSM_FEATURE_DESCRIPTION "GSM audio codec library")
358
+
359
+ set(LAME_FEATURE_TYPE "OPTIONAL")
360
+ set(LAME_FEATURE_PURPOSE "codec")
361
+ set(LAME_FEATURE_DESCRIPTION "lame MP3 audio codec library")
362
+
363
+ set(FAAD2_FEATURE_TYPE "OPTIONAL")
364
+ set(FAAD2_FEATURE_PURPOSE "codec")
365
+ set(FAAD2_FEATURE_DESCRIPTION "FAAD2 AAC audio codec library")
366
+
367
+ set(FAAC_FEATURE_TYPE "OPTIONAL")
368
+ set(FAAC_FEATURE_PURPOSE "codec")
369
+ set(FAAC_FEATURE_DESCRIPTION "FAAC AAC audio codec library")
370
+
371
+ set(SOXR_FEATURE_TYPE "OPTIONAL")
372
+ set(SOXR_FEATURE_PURPOSE "codec")
373
+ set(SOXR_FEATURE_DESCRIPTION "SOX audio resample library")
374
+
375
+ if(WIN32)
376
+ set(WAYLAND_FEATURE_TYPE "DISABLED")
377
+ set(PCSC_FEATURE_TYPE "DISABLED")
378
+ endif()
379
+
380
+ if(APPLE)
381
+ set(WAYLAND_FEATURE_TYPE "DISABLED")
382
+ if(IOS)
383
+ set(PCSC_FEATURE_TYPE "DISABLED")
384
+ endif()
385
+ endif()
386
+
387
+ if(ANDROID)
388
+ set(WAYLAND_FEATURE_TYPE "DISABLED")
389
+ set(PCSC_FEATURE_TYPE "DISABLED")
390
+ endif()
391
+
392
+ find_feature(Wayland ${WAYLAND_FEATURE_TYPE} ${WAYLAND_FEATURE_PURPOSE} ${WAYLAND_FEATURE_DESCRIPTION})
393
+
394
+ option(WITH_LIBRESSL "build with LibreSSL" OFF)
395
+ if(WITH_LIBRESSL)
396
+ find_package(LibreSSL REQUIRED)
397
+ include_directories(SYSTEM ${LibreSSL_INCLUDE_DIRS})
398
+ set(OPENSSL_INCLUDE_DIR ${LIBRESSL_INCLUDE_DIR})
399
+ set(OPENSSL_LIBRARIES ${LIBRESSL_LIBRARIES})
400
+ set(OPENSSL_CRYPTO_LIBRARIES ${LIBRESSL_LIBRARIES})
401
+ set(WITH_OPENSSL ON)
402
+ set(OPENSSL_FOUND ON)
403
+ add_compile_definitions("WITH_LIBRESSL")
404
+ add_compile_definitions("WITH_OPENSSL")
405
+ else()
406
+ find_feature(OpenSSL ${OPENSSL_FEATURE_TYPE} ${OPENSSL_FEATURE_PURPOSE} ${OPENSSL_FEATURE_DESCRIPTION})
407
+ find_feature(MbedTLS ${MBEDTLS_FEATURE_TYPE} ${MBEDTLS_FEATURE_PURPOSE} ${MBEDTLS_FEATURE_DESCRIPTION})
408
+ endif()
409
+
410
+ find_feature(PCSC ${PCSC_FEATURE_TYPE} ${PCSC_FEATURE_PURPOSE} ${PCSC_FEATURE_DESCRIPTION})
411
+
412
+ if(WITH_DSP_FFMPEG OR WITH_VIDEO_FFMPEG OR WITH_FFMPEG)
413
+ find_package(FFmpeg REQUIRED COMPONENTS AVUTIL AVCODEC)
414
+ endif()
415
+
416
+ find_feature(OpenH264 ${OPENH264_FEATURE_TYPE} ${OPENH264_FEATURE_PURPOSE} ${OPENH264_FEATURE_DESCRIPTION})
417
+ find_feature(OpenCL ${OPENCL_FEATURE_TYPE} ${OPENCL_FEATURE_PURPOSE} ${OPENCL_FEATURE_DESCRIPTION})
418
+ find_feature(GSM ${GSM_FEATURE_TYPE} ${GSM_FEATURE_PURPOSE} ${GSM_FEATURE_DESCRIPTION})
419
+ find_feature(LAME ${LAME_FEATURE_TYPE} ${LAME_FEATURE_PURPOSE} ${LAME_FEATURE_DESCRIPTION})
420
+ find_feature(FAAD2 ${FAAD2_FEATURE_TYPE} ${FAAD2_FEATURE_PURPOSE} ${FAAD2_FEATURE_DESCRIPTION})
421
+ find_feature(FAAC ${FAAC_FEATURE_TYPE} ${FAAC_FEATURE_PURPOSE} ${FAAC_FEATURE_DESCRIPTION})
422
+ find_feature(soxr ${SOXR_FEATURE_TYPE} ${SOXR_FEATURE_PURPOSE} ${SOXR_FEATURE_DESCRIPTION})
423
+
424
+ if(WITH_OPENH264 AND NOT WITH_OPENH264_LOADING)
425
+ option(WITH_OPENH264_LOADING "Use LoadLibrary to load openh264 at runtime" OFF)
426
+ endif(WITH_OPENH264 AND NOT WITH_OPENH264_LOADING)
427
+
428
+ # Version check, if we have detected FFMPEG but the version is too old
429
+ # deactivate it as sound backend.
430
+ if(WITH_DSP_FFMPEG)
431
+ if(AVCODEC_VERSION VERSION_LESS "57.48.101")
432
+ message(
433
+ WARNING
434
+ "FFmpeg version detected (${AVCODEC_VERSION}) is too old. (Require at least 57.48.101 for sound). Deactivating"
435
+ )
436
+ set(WITH_DSP_FFMPEG OFF)
437
+ endif()
438
+ endif(WITH_DSP_FFMPEG)
439
+
440
+ if(WITH_OPENH264 AND NOT OPENH264_FOUND)
441
+ message(FATAL_ERROR "OpenH264 support requested but not detected")
442
+ endif()
443
+ set(WITH_OPENH264 ${OPENH264_FOUND})
444
+
445
+ if(OPENSSL_FOUND)
446
+ add_compile_definitions("WITH_OPENSSL")
447
+ message(STATUS "Using OpenSSL Version: ${OPENSSL_VERSION}")
448
+ include_directories(SYSTEM ${OPENSSL_INCLUDE_DIR})
449
+ endif()
450
+
451
+ if(MBEDTLS_FOUND)
452
+ add_compile_definitions("WITH_MBEDTLS")
453
+ endif()
454
+
455
+ if(WITH_OPENH264 OR WITH_MEDIA_FOUNDATION OR WITH_VIDEO_FFMPEG OR WITH_MEDIACODEC)
456
+ set(WITH_GFX_H264 ON)
457
+ else()
458
+ set(WITH_GFX_H264 OFF)
459
+ endif()
460
+
461
+ # Android expects all libraries to be loadable
462
+ # without paths.
463
+ if(ANDROID OR WIN32 OR MAC_BUNDLE)
464
+ set(PLUGIN_ABS_PATHS_DEFAULT OFF)
465
+ else()
466
+ set(PLUGIN_ABS_PATHS_DEFAULT ON)
467
+ endif()
468
+ option(WITH_ABSOLUTE_PLUGIN_LOAD_PATHS "Load plugins with absolute paths" ${PLUGIN_ABS_PATHS_DEFAULT})
469
+
470
+ if(NOT WITH_ABSOLUTE_PLUGIN_LOAD_PATHS)
471
+ set(FREERDP_DATA_PATH "share")
472
+ if(NOT FREERDP_INSTALL_PREFIX)
473
+ set(FREERDP_INSTALL_PREFIX ".")
474
+ endif()
475
+ set(FREERDP_LIBRARY_PATH ".")
476
+ set(FREERDP_PLUGIN_PATH ".")
477
+ else()
478
+ set(FREERDP_DATA_PATH "${CMAKE_INSTALL_PREFIX}/share/${FREERDP_MAJOR_DIR}")
479
+ if(NOT FREERDP_INSTALL_PREFIX)
480
+ set(FREERDP_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
481
+ endif()
482
+ set(FREERDP_LIBRARY_PATH "${CMAKE_INSTALL_LIBDIR}")
483
+ if(WIN32)
484
+ set(FREERDP_PLUGIN_PATH "${CMAKE_INSTALL_BINDIR}/${FREERDP_MAJOR_DIR}")
485
+ else()
486
+ set(FREERDP_PLUGIN_PATH "${CMAKE_INSTALL_LIBDIR}/${FREERDP_MAJOR_DIR}")
487
+ endif()
488
+ endif()
489
+ set(FREERDP_ADDIN_PATH "${FREERDP_PLUGIN_PATH}")
490
+
491
+ # Path to put extensions
492
+ set(FREERDP_EXTENSION_POSTFIX "${FREERDP_MAJOR_DIR}/extensions")
493
+ set(FREERDP_EXTENSION_REL_PATH "${CMAKE_INSTALL_LIBDIR}/${FREERDP_EXTENSION_POSTFIX}")
494
+ set(FREERDP_EXTENSION_PATH "${CMAKE_INSTALL_FULL_LIBDIR}/${FREERDP_EXTENSION_POSTFIX}")
495
+
496
+ # Proxy plugins path
497
+ if(NOT DEFINED PROXY_PLUGINDIR)
498
+ message("using default plugins location")
499
+ set(FREERDP_PROXY_PLUGINDIR "${FREERDP_PLUGIN_PATH}/proxy/")
500
+ else()
501
+ set(FREERDP_PROXY_PLUGINDIR "${PROXY_PLUGINDIR}")
502
+ endif()
503
+
504
+ # Unit Tests
505
+
506
+ include(CTest)
507
+
508
+ if(BUILD_TESTING_INTERNAL OR BUILD_TESTING)
509
+ enable_testing()
510
+
511
+ if(MSVC)
512
+ set(TESTING_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
513
+ else()
514
+ set(TESTING_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Testing")
515
+ endif()
516
+ endif()
517
+
518
+ include(CommonConfigOptions)
519
+
520
+ if(FREERDP_UNIFIED_BUILD)
521
+ add_subdirectory(winpr)
522
+ if(WITH_WAYLAND)
523
+ add_subdirectory(uwac)
524
+ endif()
525
+ if(WITH_SERVER)
526
+ option(WITH_RDTK "build rdtk toolkit" ON)
527
+ if(WITH_RDTK)
528
+ add_subdirectory(rdtk)
529
+ endif()
530
+ endif()
531
+
532
+ include_directories(${PROJECT_SOURCE_DIR}/winpr/include)
533
+ include_directories(${PROJECT_BINARY_DIR}/winpr/include)
534
+ else()
535
+ find_package(WinPR 3 REQUIRED)
536
+ include_directories(SYSTEM ${WinPR_INCLUDE_DIR})
537
+ endif()
538
+
539
+ option(WITH_AAD "Compile with support for Azure AD authentication" ${WITH_WINPR_JSON})
540
+
541
+ # Include directories
542
+ include_directories(${CMAKE_CURRENT_BINARY_DIR})
543
+ include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
544
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
545
+
546
+ # Sub-directories
547
+
548
+ if(WITH_THIRD_PARTY)
549
+ add_subdirectory(third-party)
550
+ if(NOT "${THIRD_PARTY_INCLUDES}" STREQUAL "")
551
+ include_directories(SYSTEM ${THIRD_PARTY_INCLUDES})
552
+ endif()
553
+ endif()
554
+
555
+ add_subdirectory(libfreerdp)
556
+
557
+ if(WITH_CHANNELS)
558
+ add_subdirectory(channels)
559
+ endif()
560
+
561
+ if(WITH_CLIENT_COMMON OR WITH_CLIENT)
562
+ add_subdirectory(client)
563
+ endif()
564
+
565
+ if(WITH_SERVER)
566
+ add_subdirectory(server)
567
+ endif()
568
+
569
+ # Packaging
570
+
571
+ set(CMAKE_CPACK_INCLUDE_FILE "CMakeCPack.cmake")
572
+
573
+ if(NOT (VENDOR MATCHES "FreeRDP"))
574
+ if(DEFINED CLIENT_VENDOR_PATH)
575
+ if(EXISTS "${PROJECT_SOURCE_DIR}/${CLIENT_VENDOR_PATH}/CMakeCPack.cmake")
576
+ set(CMAKE_CPACK_INCLUDE_FILE "${CLIENT_VENDOR_PATH}/CMakeCPack.cmake")
577
+ endif()
578
+ endif()
579
+ endif()
580
+
581
+ #message("VENDOR: ${VENDOR} CLIENT_VENDOR_PATH: ${CLIENT_VENDOR_PATH} CMAKE_CPACK_INCLUDE_FILE: ${CMAKE_CPACK_INCLUDE_FILE}")
582
+
583
+ set(FREERDP_BUILD_CONFIG_LIST "")
584
+ get_cmake_property(res VARIABLES)
585
+ foreach(var ${res})
586
+ if(var MATCHES "^WITH_*|^BUILD_TESTING*|^WINPR_HAVE_*")
587
+ list(APPEND FREERDP_BUILD_CONFIG_LIST "${var}=${${var}}")
588
+ endif()
589
+ endforeach()
590
+ string(REPLACE ";" " " FREERDP_BUILD_CONFIG "${FREERDP_BUILD_CONFIG_LIST}")
591
+
592
+ add_subdirectory(include)
593
+
594
+ include(${CMAKE_CPACK_INCLUDE_FILE})
595
+
596
+ message(STATUS "Intrinsic path configuration:")
597
+ #ShowCMakeVars("^CMAKE_INSTALL_PREFIX")
598
+ #ShowCMakeVars("^CMAKE_INSTALL_LIBDIR")
599
+ showcmakevars("^FREERDP_INSTALL_PREFIX|^FREERDP_LIBRARY_PATH|^FREERDP_PLUGIN_PATH")
600
+ showcmakevars("^FREERDP_ADDIN_PATH|^FREERDP_EXTENSION_PATH|^FREERDP_PROXY_PLUGINDIR")
local-test-freerdp-delta-01/afc-freerdp/ChangeLog ADDED
@@ -0,0 +1,622 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2025-02-07 Version 3.11.1
2
+
3
+ A bugfix release addressing two regressions reported against 3.11.0
4
+
5
+ Noteworthy changes:
6
+ * Fix a segfault when passing /pth (#11138)
7
+ * Fix a regression in planar codec (#11136)
8
+
9
+ For a complete and detailed change log since the last release run:
10
+ git log 3.11.1...3.11.0
11
+
12
+ # 2025-02-06 Version 3.11.0
13
+
14
+ A new release with bugfixes and code cleanups as well as a few nifty little
15
+ features that will improve your meetings.
16
+
17
+ Noteworthy changes:
18
+ * Updated android client to more recent gradle (#11105, #11110)
19
+ * Fix cmake clean target (#109
20
+ * SDL3 bugfixes and API updates (#11092, #11093, #11128)
21
+ * Fix keyboard mapping, add working japanese and korean types, deprecate
22
+ obsolete functions (#10989, #11035, #11011, #11074, #11037)
23
+ * Fix timezone mapping and iteration (#11077, #11079, #11080, #11083)
24
+ * Fix YUV reverse filter for AVC444 modes (#11045, #11063, #11066, #11081, #11086,
25
+ #11087)
26
+ * Fix H.264 encoder wrapper issues (#11117, #11121, #11078)
27
+ * MS-RDPECAM: Support for H.264 encoding with VA-API (#10887)
28
+ * Fix various CMake, build script and github workflow issues (#10992, #10996,
29
+ #11020, #11031, #11030, #11062, #11064, #11069, #11073, #11123, #11109,
30
+ #11120, #11053, #11089)
31
+ * [codec,planar] fix decoder regression (#11033)
32
+ * [client,cmdline] fix vmconnect checks (#11051)
33
+ * Fix multi-monitor related checks (#11095)
34
+ * Fix various compiler and clang-tidy warnings (#10953, #11003, #11004,
35
+ #11007, #11016, #11018, #11019, #11021, #11017, #11000, #11023, #11024,
36
+ #11026, #11002, #11028, #11001, #11029, #10999, #11006, #11034, #10998,
37
+ #11044, #11050, #11052, #11057, #11059, #11065, #11067, #11068, #11060,
38
+ #11071, #11085, #11088, #11099, #11102, #11108, #11124, #11126, #11129,
39
+ #11130)
40
+
41
+ New Contributors
42
+ * @chewi made their first contribution in https://github.com/FreeRDP/FreeRDP/pull/11004
43
+ * @gpotter2 made their first contribution in https://github.com/FreeRDP/FreeRDP/pull/11016
44
+ * @vmpn made their first contribution in https://github.com/FreeRDP/FreeRDP/pull/11092
45
+
46
+ For a complete and detailed change log since the last release run:
47
+ git log 3.11.0...3.10.3
48
+
49
+
50
+ # 2024-12-17 Version 3.10.3
51
+
52
+ Follow up release to 3.10.2, as we've discovered a few bugs after release.
53
+
54
+ Noteworthy changes:
55
+ * Fix usage of GetComputerNameExA (#10988)
56
+ * Fix cmake clean target (#10990)
57
+
58
+ For a complete and detailed change log since the last release run:
59
+ git log 3.10.3...3.10.2
60
+
61
+ # 2024-12-16 Version 3.10.2
62
+
63
+ Follow up release to 3.10.1, as we've discovered a few bugs during release
64
+ tests.
65
+
66
+ Noteworthy changes:
67
+ * Fix initializing ComputerName setting (#10985)
68
+ * Fix some warnings and possible leaks (#10985)
69
+
70
+ For a complete and detailed change log since the last release run:
71
+ git log 3.10.2...3.10.1
72
+
73
+ # 2024-12-16 Version 3.10.1
74
+
75
+ We're happy to present a new release of FreeRDP.
76
+ This release contains a few fixes for bugs revealed by checks introduced
77
+ with 3.10.0
78
+
79
+ Noteworthy Changes:
80
+ * Add FreeBSD as architecture build to our ci (#10980 and others)
81
+ * Fix empty include directory creation (#10981)
82
+ * fix SIMD detection (#10968)
83
+ * improve settings unit test coverage (#10966)
84
+ * fix sending server redirection PDU (#10963)
85
+ * fix return and use of GetComputerNameA (#10962)
86
+
87
+ For a complete and detailed change log since the last release run:
88
+ git log 3.10.1...3.10.0
89
+
90
+ # 2024-12-12 Version 3.10.0
91
+
92
+ We're happy to present a new release of FreeRDP.
93
+ This one contains some more code cleanups (we've addressed lots of clang-tidy
94
+ warnings) as well as some highly anticipated new features and bugfixes.
95
+
96
+ So, what is new:
97
+ * Enforce use of a supported build type (#10777)
98
+ * Enable FDK-AAC support for nightly packages (#10875, #10781)
99
+ * Better AAD/AVD support (#10796)
100
+ * Build system updates (#10844)
101
+ * Enforce spell checking (#10881)
102
+ * Split unit tests so a subset can be run during package build (#10776)
103
+ * We're shipping a .desktop file now (#10465)
104
+ * Build scripts for nightly packages (#10835, #10783)
105
+
106
+ Noteworthy changes:
107
+ * Fix wStream API bugs (#10885)
108
+ * Autoreconnect fixes (#10915)
109
+ * Fix monitor layout checks (#10905)
110
+ * Enforce code formatting for CMake files (#10895)
111
+ * Enable SIMD optimizations by default (#10894)
112
+ * WinPR types not based on stdint.h et al (#10754)
113
+ * Improve code assertions (#10768)
114
+ * Code cleanups (#10763, #10914)
115
+
116
+ For a complete and detailed change log since the last release run:
117
+ git log 3.10.0...3.9.0
118
+
119
+
120
+ # 2024-10-21 Version 3.9.0
121
+
122
+ We're proud to present the newest release of FreeRDP.
123
+ This one brings some major code cleanup (we've addressed lots of clang-tidy
124
+ warnings) as well as some highly anticipated new features.
125
+ We also did update the API documentation quite a bit (still incomplete though,
126
+ help always welcome ;))
127
+
128
+ So, what is new:
129
+ * Support for RDPEAR (remote credential guard) /remoteGuard option for non windows clients
130
+ * Global configuration file support, allowing to configure certificate
131
+ accept/ignore/... default settings for all users
132
+ * Simplified manpage generation, eliminates docbook and xmlto dependencies
133
+ speeding up builds
134
+ * New API for client channels to run tasks on RDP thread
135
+ * New extended transport layer API
136
+ * RDPECAM MJPEG support
137
+ * the first updates of timezone definitions from our automated ci
138
+
139
+ Noteworthy changes:
140
+ * Fix bugs in SSE4.1/AVX2 image copy (#10720)
141
+ * Add warnings for invalid monitor settings during connect (#10672)
142
+ * Fix ALSA microphone support (#10664)
143
+ * Fix modal windows in RAILS mode (#10629)
144
+ * Update experimental SDL3 client (SDL3 API should now have been stabilized,
145
+ various pull requests)
146
+ * Fix keyboard layouts, the external JSON did miss a few (#10639)
147
+
148
+ For a complete and detailed change log since the last release run:
149
+ git log 3.9.0...3.8.0
150
+
151
+ # 2024-08-30 Version 3.8.0
152
+
153
+ This is a bugfix release. Due to additional exports required by a bugfix the minor version was incremented
154
+
155
+ Noteworthy changes:
156
+ * Reduce number of warnings on CI build (make dependency includes SYSTEM) (#10509)
157
+ * Fix possible crashes with P11 certificate parsing (#10462, #10463)
158
+ * Various clipboard related fixes (#10472, #10476, #10477, #10480, #10484)
159
+ * Fix a race condition on DesktopResize (xfreerdp) (#10488)
160
+ * Improve certificate warnings (#10489)
161
+ * Try all possible resolved IP addresses for a DNS name on connect (#10491)
162
+ * Fix an issue with GFX SolidFill alpha data (#10498)
163
+ * Various fixes for SDL clients (#10504, #10492, #10471)
164
+ * Fix serial and parallel redirection crashes (#10510)
165
+ * Fix android build issues with NDK 27 (#10529)
166
+ * Improve performance of some WinPR primitives (#10528)
167
+ * Fix an issue with autoreconnect (#10523)
168
+ * Support ssh-askpass like password reading (#10516)
169
+ * Lots of code cleanups to reduce clang-tidy warnings (#10531, #10525, #10521, #10520, #10519, #10518)
170
+
171
+ For a complete and detailed change log since the last release run:
172
+ git log 3.8.0...3.7.0
173
+
174
+ # 2024-08-08 Version 3.7.0
175
+
176
+ This release has accumulated quite a number of changes. Along bugfixes for 3.6.3 it also
177
+ contains a number of improvements for distributors:
178
+
179
+ * Support for FDK-AAC for sound and microphone redirection (activate with -DWITH_FDK_AAC=ON build option)
180
+ This allows enabling the AAC compression that do not ship faad2 and/or faac
181
+ * Support keyboard layouts as JSON resources (activate with -DWITH_KEYBOARD_LAYOUT_FROM_FILE=ON build option,
182
+ also requires JSON support)
183
+ This allows editing keyboard layouts for existing releases should the need arise
184
+ * Support timezones as JSON resources (activate with -DWITH_TIMEZONE_FROM_FILE=ON -DWITH_TIMEZONE_COMPILED=OFF build options,
185
+ also requires JSON support)
186
+ Allows reading the mapping between IANA and windows timezones from a JSON file, allowing easier updates without recompile
187
+ * Improve shadow server compatibility with windows 11 24H2 RDP client
188
+ Windows 7 RFX and bitmap updates with multiple rectangles have been deactivated, so adjust shadow to not send such.
189
+
190
+ Noteworthy changes:
191
+ * Fix ActionScript parameter (#10423)
192
+ * Support keyboard layouts as JSON resource (#10394)
193
+ * Support timezones as JSON resource and command line argument (#10428 #10393 #10391)
194
+ * Deactivate AsyncUpdate (#10402)
195
+ * Compatibility fixes for shadow with windows 11 24H2 (#10455 #10422 #10420 #10416)
196
+ * Fix SDL client autoreconnect (#10390)
197
+ * Fix xfreerdp clipboard locking (#10385)
198
+ * Improve logging (#10426 #10441)
199
+ * Improve warnings and code checks (#10381 #10401 #10403 #10405 #10406 #10410 #10421 #10454)
200
+ * Support FDK-AAC (#10372)
201
+ * Fix drive redirection state transitions (#10367 #10374)
202
+ * Support mth:// routing token (#10366)
203
+ * Ignore unsupported SetThreadPriority (#10363)
204
+ * Fix reported documentation and code typos (#10365 #10368 #10370 #10369 #10431 #10446)
205
+
206
+ For a complete and detailed change log since the last release run:
207
+ git log 3.7.0...3.6.3
208
+
209
+ # 2024-07-08 Version 3.6.3
210
+
211
+ Bugfix release for 3.6.2 issues reported
212
+
213
+ Noteworthy changes:
214
+ * fix a graphics regression (#10352)
215
+ * workaround for a protocol bug of older FreeRDP based servers (#10358)
216
+ * fix possible NULL dereference in command line parser (#10348)
217
+ * fix intrinsics detection (#10346, #10350)
218
+
219
+ For a complete and detailed change log since the last release run:
220
+ git log 3.6.3...3.6.2
221
+
222
+
223
+ # 2024-07-04 Version 3.6.2
224
+
225
+ Bugfix release for 3.6.1 issues detected during release tests
226
+
227
+ Noteworthy changes:
228
+ * Fix xfreerdp and sdl-freerdp manpage names (accidentally changed name)
229
+ * Fix crash of wfreerdp
230
+
231
+ For a complete and detailed change log since the last release run:
232
+ git log 3.6.2...3.6.1
233
+
234
+
235
+ # 2024-07-04 Version 3.6.1
236
+
237
+ Bugfix release for 3.6.0
238
+
239
+ Noteworthy changes:
240
+ * Fix missing dependency for ci abi-checker
241
+ * Fix build WITH_SSE2/WITH_NEON: only enable support if the compiler
242
+ also defines symbols that suggest support.
243
+ * Fix incomplete changelog for 3.6.0:
244
+ * Improved image copy (#10208)
245
+ * Experimental [MS-RDPECAM] support by @oleg0421 (#10258)
246
+ * Improved primitives (#10304)
247
+ * Connection timeout for HTTP gateway transport (#10288)
248
+
249
+ For a complete and detailed change log since the last release run:
250
+ git log 3.6.1...3.6.0
251
+
252
+
253
+ # 2024-07-03 Version 3.6.0
254
+
255
+ With this release we did improve decoder speed so you should notice a significant
256
+ speed improvement with progressive and other gfx codecs.
257
+ We've also eliminated a couple of issues along the way, so an update
258
+ is highly recommended.
259
+
260
+ Noteworthy changes:
261
+ * Improved command line failure logging (#10333)
262
+ * p11-kit support (#10081)
263
+ * json-c support (#10183)
264
+ * (experimental) SDL3 port SDL client (#10195)
265
+ * New option '/gfx:frame-ack:off' for connection delay testing (#10214)
266
+ * improved decoder speed (#10222, #10235)
267
+ * xfreerdp floatbar hide bug (#10237)
268
+ * winpr-makecert month bug (#10236)
269
+ * kerberos kdcUrl check fixes (#10238)
270
+ * timezone updates (#10120, #10144, #10170)
271
+ * fixed a capability protocol violation bug (#10132)
272
+ * fix SDL client dialog bug terminating on credential dialog (#10134)
273
+ * some more oss-fuzz issues (#10126, #10141, #10148, #10161, #10239)
274
+ * rails popup window fixes (#10160)
275
+
276
+
277
+ For a complete and detailed change log since the last release run:
278
+ git log 3.6.0...3.5.1
279
+
280
+
281
+ # 2024-04-22 Version 3.5.1
282
+
283
+ This release eliminates a bunch of issues detected during oss-fuzz runs.
284
+ The test coverage was increased and detected issues eliminates, so an update
285
+ is highly recommended.
286
+
287
+ Noteworthy changes:
288
+ * Lots of fixes for oss-fuzz reports
289
+ * Timezone detection fixes (#10106)
290
+ * SDL key remapping support (#10103)
291
+ * Improved help (#10099)
292
+ * FreeBSD epoll detection fix (#10097)
293
+
294
+ For a complete and detailed change log since the last release run:
295
+ git log 3.5.1...3.5.0
296
+
297
+ # 2024-04-16 Version 3.5.0
298
+
299
+ This release focus is on squashing bugs.
300
+ The improved test coverage and ci builds revealed a number of previously
301
+ unnoticed issues we have addressed and we also got a report from
302
+ Evgeny Legerov of Kaspersky Lab identifying a number of out of bound reads
303
+ in decoder components and one very nasty out of bound write.
304
+
305
+ CVE:
306
+ CVE-2024-32041 [Low[ OutOfBound Read in zgfx_decompress_segment
307
+ CVE-2024-32039 [Moderate] Integer overflow & OutOfBound Write in clear_decompress_residual_data
308
+ CVE-2024-32040 [Low] integer underflow in nsc_rle_decode
309
+ CVE-2024-32458 [Low] OutOfBound Read in planar_skip_plane_rle
310
+ CVE-2024-32459 [Low] OutOfBound Read in ncrush_decompress
311
+ CVE-2024-32460 [Low] OutOfBound Read in interleaved_decompress
312
+
313
+ Noteworthy changes:
314
+ * location channel support #9981, #9984, #10065
315
+ * bugfixes for report from Evgeny Legerov of Kaspersky Lab #10077
316
+ * fuzzer tests from Evgeny Legerov of Kaspersky Lab #10078
317
+ * bugfixes for coverty scanner #10066, #10068, #10069, #10070, #10075
318
+ * clipboard and generic locking fixes #10076
319
+ * split autoreconnect support from enabling it #10063
320
+ * various nightly and workflow fixes #10064, #10058, #10062
321
+ * always set wm-class to app_id #10051
322
+ * refactored and simplified CMake #10046, #10047
323
+ * fix relative mouse event sending #10010
324
+ * improve and unify check for APIs used (POSIX, win32, mac, ...) #9995
325
+ * fix termination for gateway connections #9985
326
+ * fix drivestoredirect RDP file setting, ignore invalid #9989
327
+ * drop IPP support #10038
328
+
329
+ For a complete and detailed change log since the last release run:
330
+ git log 3.5.0...3.4.0
331
+
332
+ # 2024-03-14 Version 3.4.0
333
+
334
+ This release concentrates on improving test coverage and ci builds.
335
+ Some usability issues and inconvenient API functions were fixed on the way.
336
+
337
+ New features have been introduced (stub for location channel)
338
+
339
+ Noteworthy changes:
340
+ * fix a bug in RAIL mode not activating window focus (#9973)
341
+ * improve logging (#9969, #9943)
342
+ * OpenSSL <= 1.1.1 build fixes (#9897)
343
+ * improved help (#9899, #9905)
344
+ * improved MINGW support (#9914, #9915, #9919, #9964, #9965, #9920)
345
+ * fix right control ungrab for xfreerdp (#9960)
346
+ * fix RPATH option settings (#9963)
347
+ * fix SDL client screen updates (#9962, #9954)
348
+ * fix issues with childSession under windows (#9961, #9956, #9922)
349
+ * fix xfreerdp crash with +auth-only (#9947)
350
+ * fix windows printer channel (#9934)
351
+ * add support to enforce gateway policy (#9942)
352
+ * improve big endian support (#9927)
353
+ * ignore empty proxy environment variables (#9929)
354
+ * improve quoting support for command line (#9912)
355
+
356
+ For a complete and detailed change log since the last release run:
357
+ git log 3.4.0...3.3.0
358
+
359
+
360
+ # 2024-02-22 Version 3.3.0
361
+
362
+ This release concentrates on code cleanup and overall quality improvements.
363
+ Some usability issues and inconvenient API functions were fixed on the way.
364
+
365
+ New features have been introduced (better image clipboard) but that stays
366
+ deactivated by default as we´re in a stable series.
367
+
368
+ Check the new CMake options:
369
+ * PLUGIN_ABS_PATHS_DEFAULT disables loading of external channels from all
370
+ but a specified absolute plugin directory defined by FREERDP_PLUGIN_PATH
371
+ * WINPR_UTILS_IMAGE_PNG enables PNG support with libpng in winpr image/clipboard
372
+ * WITH_LODEPNG enables PNG support with lodepng library in winpr image/clipboard
373
+ * WINPR_UTILS_IMAGE_WEBP enables WEBP support in winpr image/clipboard
374
+ * WINPR_UTILS_IMAGE_JPEG enables JPEG support in winpr image/clipboard
375
+ * USE_EXECINFO enables or disables backtrace support with execinfo
376
+ * WITH_WEBVIEW now defaults to OFF on windows, apple and android (not implemented)
377
+
378
+ Noteworthy changes:
379
+ * Improved image clipboard (xfreerdp, wlfreerdp) (#9873, #9826)
380
+ * Improved SDL client (#9875, #9887, #9883, #9878, #9792)
381
+ * Allow plugin loader to only use absolute paths (#9809)
382
+ * Improved TLS channel binding (#9838)
383
+ * Add GCC/clang attribute malloc wrapper WINPR_ATTR_MALLOC (#9863)
384
+ * Major clang-tidy code cleanups and bugfixes (#9799, #9834)
385
+ * Provide some defaults for wObject functions (#9799)
386
+ * Fix a bug in shadow with GFX breaking mstsc (#9818)
387
+ * Improved manpages and help (#9813, #9804)
388
+ * Blocking mode via transport IO interface (#9793)
389
+
390
+ For a complete and detailed change log since the last release run:
391
+ git log 3.3.0...3.2.0
392
+
393
+ # 2024-01-19 Version 3.2.0
394
+
395
+ This release mostly addresses issues reported since the last release.
396
+ Fixing some usablity and build issues as well as adding API functions
397
+ that are needed from external projects
398
+
399
+ Noteworthy changes:
400
+ * Fix proxy module load check (#9777)
401
+ * Improve kerberos error logging (#9771)
402
+ * Improve mac client keyboard handling (#9767)
403
+ * Add option to run client dynamic channel synchronous (#9764)
404
+ * Move huge struct to heap (#9763)
405
+ * Improved failure logging of license module (#9759)
406
+ * Improve server side gfx logging (#9757)
407
+ * Print shadow server help with printf instead of WLog (#9756)
408
+ * Fix SDL client timer initialization (#9754)
409
+ * Fix server peer message parsing (#9751)
410
+ * Enable NEON instructions if __ARM_NEON is defined (#9748)
411
+ * Add new proxy config file option TlsSecLevel (#9741)
412
+ * Improve android and mac os build scripts (#9735)
413
+ * Do not disable wayland support on BSD (#9730)
414
+ * Fix issues with assistance file parsing (#9727, #9728)
415
+ * Keyboard handling fixes for wayland client (#9725)
416
+ * Fix relative pkg-config file paths (#9720)
417
+ * Add new transport IO callback GetPublicKey (#9719)
418
+ * Fix wayland client scaling (#9715)
419
+
420
+ For a complete and detailed change log since the last release run:
421
+ git log 3.2.0...3.1.0
422
+
423
+ # 2023-12-22 Version 3.1.0
424
+
425
+ A new 3.1.0 minor release for the new 3.0.0 series.
426
+ This contains bugfixes, adds (better) support for libressl and mbedtls and
427
+ brings a bunch of improvements for the SDL client.
428
+
429
+ This comes with a price though, we now (optionally) require SDL_image if you
430
+ want to build the sdl-client
431
+
432
+ Since there are multiple new features, some new files (man pages) and new
433
+ optional dependencies we´ve directly incremented the minor version.
434
+
435
+ New CMake options:
436
+ * SDL_USE_COMPILED_RESOURCES (default ON) builds fonts and images into SDL
437
+ client. Set to OFF to install these resources as files. (was already part of
438
+ 3.0.0, but worth mentioning here)
439
+ * WITH_SDL_IMAGE_DIALOGS (default OFF) Show some nice icons for SDL client
440
+ connection dialogs. Requires SDL_image for build.
441
+ * WITH_BINARY_VERSIONING (default OFF) Similar as for libraries the binaries,
442
+ manpages and resource locations created by FreeRDP project are postfixed
443
+ with the API version. Recommended if packagers want to install the package
444
+ alongside FreeRDP 2 without conflicts.
445
+ * RDTK_FORCE_STATIC_BUILD (default OFF) Build and link RDTK statically into
446
+ shadow server. Recommended for packagers as this library is not really used
447
+ outside of FreeRDP-shadow.
448
+ * UWAC_FORCE_STATIC_BUILD (default OFF) Build and link UWAC statically into
449
+ wlfreerdp. Recommended for packagers as this library is not really used
450
+ outside of wlfreerdp.
451
+
452
+ Noteworthy changes:
453
+ * Fix a nasty bug with relative mouse movement (#9677)
454
+ * LibreSSL support enhancements (#9691, #9670)
455
+ * mbedTLS support enhancements (#9662)
456
+ * Improve building on mac OS (#9641)
457
+ * New and improved manpages (#9690, #9650)
458
+ * Unify CMake common options, add (optional) binary versioning and allow
459
+ building rdtk and uwac as static dependencies (#9695)
460
+ * SDL client improvements (#9693, #9657, #9659, #9683, #9680, #9657, #9664,
461
+ #9656)
462
+
463
+ For a complete and detailed change log since the last release run:
464
+ git log 3.1.0...3.0.0
465
+
466
+ # 2023-12-12 Version 3.0.0
467
+
468
+ Final 3.0.0 release just a little over two weeks after the last 3.0.0-rc0.
469
+ This contains bugfixes, drops some legacy code, implements a small feature
470
+ request and adds some improvements to the build system.
471
+
472
+ Most notably is the new PreventInSourceBuilds.cmake which does exactly what
473
+ the name implies, it aborts builds where source equals build directory.
474
+ If you can not use out of source tree builds for some reason, you can
475
+ circumvent this measure with the CMake setting -DALLOW_IN_SOURCE_BUILD=ON
476
+
477
+ Noteworthy changes:
478
+ * add support for AF_VSOCK #9561
479
+ * xfreerdp drop X11 GDI implementation #9492
480
+ * fixed connection freeze with childSession #9594
481
+ * fixed relative mouse input issues #9608
482
+ * fixed issues with drive redirection #9610
483
+ * simplified mac build #9601
484
+ * fixed TSMF to build again #9603
485
+ * fixed command line /gfx parsing bug #9598
486
+ * prevent in source tree build #9550
487
+ * fixed various issues with settings #9595, #9596
488
+ * add E2K cpu support in WinPR #9599
489
+ * fixed wfreerdp DPI settings when used as embedded window #9593
490
+ * android add mouse hover support #9495
491
+
492
+ For a complete and detailed change log since the last release run:
493
+ git log 3.0.0..3.0.0-rc0
494
+
495
+ # 2023-11-27 Version 3.0.0-rc0
496
+
497
+ Nearly 2 months of testing, bugfixing and API refinements later we´re
498
+ happy to announce the first release candidate for FreeRDP 3.0
499
+ The API should now be considered stable and only minor changes (if at all)
500
+ will happen from this point on, so every project using FreeRDP can check
501
+ compatibility with upcoming 3.0
502
+
503
+ Noteworthy changes:
504
+ * Updated rdpSettings API #9465:
505
+ * getter/setter now use enum types for keys (generates compiler warnings for mismatch)
506
+ * Refined functions (added missing, dropped problematic ones)
507
+ * prepared opaque settings (direct struct access now deprecated)
508
+ * Server side [MS-RDPEL] channel #9471
509
+ * Relative mouse movement support #9459
510
+ * relocatable pkg-config files (enable with -DPKG_CONFIG_RELOCATABLE=ON, #9453)
511
+ * cliprdr dropped support for fuse2 (#9453)
512
+ * added support for uriparser for clipboard file:// parsing (#9455)
513
+ * aFreeRDP translation for traditional chinese (zh-rTW) added (#9450)
514
+ * fixed sdl-freerdp crash on credential dialog (#9455)
515
+ * fixed sdl-freerdp alt+tab in fullscreen (#9442)
516
+ * added /connect-child-session option (WIN32 only, #9427)
517
+ * fix rfx-image codec setup (#9425)
518
+ * added missing cmake configuration for winpr-tools (#9453)
519
+ * cleaned up cmake configuration files, dropped no longer required ones (#9455)
520
+ * fixed x11 keyboard layout detection (#9433)
521
+ * add missing API calls for server implementation (tested against ogon, #9453)
522
+ * keep dynamic channels in a hash table instead of a list (#9448)
523
+ * keep TSCredentials in server peer instance (#9430)
524
+ * fix FFMPEG/AAC encoding (#9576)
525
+ * support remote credential guard (#9574)
526
+ * fix printing on mac os 14 (#9569)
527
+ * improve RPC gateway support (#9508)
528
+ * add opus audio support for gnome-remote-desktop (#9575)
529
+ * server side handling of mouse cursor channel [MS-RDPEMSC] (#9513)
530
+
531
+ For a complete and detailed change log since the last release run:
532
+ git log 3.0.0-rc0..3.0.0-beta4
533
+
534
+ # 2023-09-31 Version 3.0.0-beta4
535
+
536
+ Noteworthy changes:
537
+ * Improved and fixed AVD authentication, now allows retries for
538
+ machines just starting up
539
+ * Improve RDP file parser, prepare new fields used by AVD
540
+ * Fixed and improved pen support in multitouch implementation (xfreerdp)
541
+ * Lots of smaller code and leak cleanups
542
+
543
+ For a complete and detailed change log since the last release run:
544
+ git log 3.0.0-beta4..3.0.0-beta3
545
+
546
+ # 2023-08-31 Version 3.0.0-beta3
547
+
548
+ Noteworthy changes:
549
+ * fix xfreerdp keyboard on mac os
550
+ * Various crashes and input check fixes
551
+ * Improved logging of autodetect, redirection and fastpath failures
552
+ * Smartcard emulation now selectable at runtime
553
+ * Allow certificates without a subject to pass client checks
554
+ * Fix FindFirstFile issues on android
555
+ * Add FREERDP_ENTRY_POINT to silence -Wmissing-prototypes warnings for
556
+ library entry points
557
+ * Add WINPR_RESTRICT to enable restrict (C99) or __restring (MSVC)
558
+ keywords for compiler
559
+ * Fix support for older OpenSSL versions
560
+
561
+ For a complete and detailed change log since the last release run:
562
+ git log 3.0.0-beta3..3.0.0-beta2
563
+
564
+ # 2023-08-03 Version 3.0.0-beta2
565
+
566
+ Noteworthy changes:
567
+ * Update CMake defaults, now all features are enabled by default with a platform
568
+ independent option if multiple are available.
569
+ * SDL client: (basic) multimonitor support
570
+ * SDL client: fix dialog cleanup order (crash fix)
571
+ * clipboard: fix FUSE shutdown crash
572
+ * fixed drive redirection: FindNextFile did miss some files/directories
573
+ * improved AAD support: honor rdp file options
574
+ * improved (gateway) http failure logging
575
+ * improved shadow server error handling
576
+ * improved CMake configuration (using find_dependency)
577
+ * updated timezone definitions
578
+ * mbedTLS build fixed
579
+ * improved MINGW build support
580
+
581
+ For a complete and detailed change log since the last release run:
582
+ git log 3.0.0-beta2..3.0.0-beta1
583
+
584
+ # 2023-07-21 Version 3.0.0-beta1
585
+
586
+ We are pleased to announce the first beta release for the next stable 3.0
587
+ series of FreeRDP. It has been a huge endeavour to implement all the new
588
+ shiny bells and whistles as well as clean up the code base and we´re still
589
+ ironing out some smaller glitches.
590
+ This is the first API breaking change since the 2.0 series and there are
591
+ some adjustments to be made for existing applications.
592
+ See https://github.com/FreeRDP/FreeRDP/wiki/FreeRDP3-migration-notes for
593
+ help (still incomplete)
594
+
595
+ Noteworthy changes:
596
+ * Support for AAD/AVD authentication
597
+ * Support for websocket transport
598
+ * Support smartcard authentication (TLS and NLA)
599
+ * Full smartcard emulation support (login with certificate + key)
600
+ * Rewritten proxy, new module API
601
+ * New reference client based on SDL2 (work in progress)
602
+ * Rewritten logging, now parsing issues are all writing to the log so
603
+ that issues with protocol incompatibilities can be easier analyzed
604
+ by just turning on logging
605
+ * Full OpenSSL 3 support
606
+ * Internal implementations for RC4, MD4 and MD5 (required for non critical
607
+ parts in RDP but not part of more recent SSL libraries)
608
+ * Updated RDP protocol support
609
+ * Improved xfreerdp remote app support
610
+ * Reworked internal state machine for both client and server implementations
611
+ * Server implementations can now make use of connect-time network autodetection
612
+ * Improved clipboard handling, now also support server-to-client file transfer
613
+ (currently xfreerdp only)
614
+ * EnhancedRemoteApp support: Utilizing the more modern standard allows remote
615
+ apps with less glitches and window shadows
616
+ * Added client- and server-side handling for RDSTLS
617
+ * Support for the graphics redirection channel
618
+
619
+ For a complete and detailed change log since the last release run:
620
+ git log 3.0.0-beta1..2.10.0
621
+
622
+
local-test-freerdp-delta-01/afc-freerdp/LICENSE ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
local-test-freerdp-delta-01/afc-freerdp/README.md ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FreeRDP: A Remote Desktop Protocol Implementation
2
+
3
+ FreeRDP is a free implementation of the Remote Desktop Protocol (RDP), released under the Apache license.
4
+ Enjoy the freedom of using your software wherever you want, the way you want it, in a world where
5
+ interoperability can finally liberate your computing experience.
6
+
7
+ ## Code Quality Status
8
+
9
+ [![abi-checker](https://github.com/FreeRDP/FreeRDP/actions/workflows/abi-checker.yml/badge.svg)](https://github.com/FreeRDP/FreeRDP/actions/workflows/abi-checker.yml)
10
+ [![clang-tidy-review](https://github.com/FreeRDP/FreeRDP/actions/workflows/clang-tidy.yml/badge.svg?event=pull_request_target)](https://github.com/FreeRDP/FreeRDP/actions/workflows/clang-tidy.yml)
11
+ [![CodeQL](https://github.com/FreeRDP/FreeRDP/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/FreeRDP/FreeRDP/actions/workflows/codeql-analysis.yml)
12
+ [![mingw-builder](https://github.com/FreeRDP/FreeRDP/actions/workflows/mingw.yml/badge.svg)](https://github.com/FreeRDP/FreeRDP/actions/workflows/mingw.yml)
13
+ [![[arm,ppc,ricsv] architecture builds](https://github.com/FreeRDP/FreeRDP/actions/workflows/alt-architectures.yml/badge.svg)](https://github.com/FreeRDP/FreeRDP/actions/workflows/alt-architectures.yml)
14
+ [![[freebsd] architecture builds](https://github.com/FreeRDP/FreeRDP/actions/workflows/freebsd.yml/badge.svg)](https://github.com/FreeRDP/FreeRDP/actions/workflows/freebsd.yml)
15
+ [![coverity](https://scan.coverity.com/projects/616/badge.svg)](https://scan.coverity.com/projects/freerdp)
16
+
17
+ ## Resources
18
+
19
+ Project website: https://www.freerdp.com/
20
+ Issue tracker: https://github.com/FreeRDP/FreeRDP/issues
21
+ Sources: https://github.com/FreeRDP/FreeRDP/
22
+ Downloads: https://pub.freerdp.com/releases/
23
+ Wiki: https://github.com/FreeRDP/FreeRDP/wiki
24
+ API documentation: https://pub.freerdp.com/api/
25
+
26
+ Security policy: https://github.com/FreeRDP/FreeRDP/security/policy
27
+
28
+ Matrix room : #FreeRDP:matrix.org (main)
29
+ XMPP channel: #FreeRDP#[email protected] (bridged)
30
+ IRC channel : #freerdp @ irc.oftc.net (bridged)
31
+ Mailing list: https://lists.sourceforge.net/lists/listinfo/freerdp-devel
32
+
33
+ ## Microsoft Open Specifications
34
+
35
+ Information regarding the Microsoft Open Specifications can be found at:
36
+ https://www.microsoft.com/openspecifications/
37
+
38
+ A list of reference documentation is maintained here:
39
+ https://github.com/FreeRDP/FreeRDP/wiki/Reference-Documentation
40
+
41
+ ## Compilation
42
+
43
+ Instructions on how to get started compiling FreeRDP can be found on the wiki:
44
+ https://github.com/FreeRDP/FreeRDP/wiki/Compilation
local-test-freerdp-delta-01/afc-freerdp/SECURITY.md ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FreeRDP Security Policies and Procedures
2
+
3
+ This document describes the security policy and procedures for the [FreeRDP Project](https://github.com/FreeRDP/FreeRDP).
4
+ The following topics are covered:
5
+
6
+ * [Supported Versions](#supported-versions)
7
+ * [Reporting a Vulnerability](#reporting-a-vulnerability)
8
+ * [Disclosure Procedure](#disclosure-procedure)
9
+
10
+
11
+ ## Supported versions
12
+
13
+ Security is very important for us therefore we try to provide security updates and support for
14
+ the latest stable version as well as for the development branch.
15
+ Since our development branch is, like the protocol itself, a moving target we won't request CVEs for issues that are *only* found on the development branch.
16
+
17
+ The following table shows the currently supported versions:
18
+
19
+ | Version | Branch | Supported |
20
+ | ------- |--------------| ------------------ |
21
+ | < 2.0.0 | stable-1.x | :x: |
22
+ | 2.x.x | stable-2.0 | :heavy_check_mark: |
23
+ | 3.x.x | stable-3.0 | :white_check_mark: |
24
+ | - | master | :white_check_mark: |
25
+
26
+
27
+ ## Reporting a vulnerability
28
+
29
+ **IMPORTANT**: Please, do not file security vulnerabilities as public issues on GitHub
30
+
31
+ In advance: **Thank you** for reporting a security vulnerability and making FreeRDP more stable! We really appreciate your effort.
32
+ Please let us know who we should give the credit or attributions to.
33
+
34
+
35
+ If you have found a security vulnerability in FreeRDP you can either directly open an [Advisory on GitHub](https://github.com/FreeRDP/FreeRDP/security/advisories/new)[^1] or send us an email to mailto:[email protected]
36
+
37
+ In case of an email you can use the [FreeRDP security team GPG key](#reporting-gpg-key) for encrypted communication.
38
+
39
+ Once we receive a report we will review it and respond as soon as possible.
40
+
41
+ ###
42
+
43
+
44
+ ## Disclosure procedure
45
+
46
+ When the FreeRDP team receives a report one of the team members will be assigned as primary contact.
47
+ The primary contact will do all further communications and coordinate the fix and release process.
48
+
49
+ How your report will be handled:
50
+
51
+ * When a report is received we will acknowledge the reception and review the reported issue(s) as soon as possible.
52
+ * Once confirmed we will determine the affected versions. If not reported via GitHub a [security advisory draft on GitHub](https://github.com/FreeRDP/FreeRDP/security/advisories) will be created for any issue. If it applies we will request a CVE.
53
+ * On a private branch we will fix the issue and check the code for any potential similar problem.
54
+ * After the fix is validated we will create and publish a new release for all supported versions and publish the advisories.
55
+
56
+ ## Reporting GPG key
57
+
58
+ FreeRDP's security reporting public gpg key https://pub.freerdp.com/FreeRDP-security-team.pub.asc
59
+
60
+ ```
61
+ -----BEGIN PGP PUBLIC KEY BLOCK-----
62
+
63
+ mQINBGBz+jsBEADaIM94hYfn/xDzncQwXl7/q6+06+ssqO3iUGqFr+0EPS+HxRjD
64
+ BeKjVRSkuo0+QLQoZgCwkoltEj1xRWNqCTDMA+oZkZH8L82eqCnUQqgCOyNWAVMH
65
+ 6u6ValiZH3ruYxergBBHhyR4Ot2ia0xWN8MKTp+emLpzQ7goimGMo0mxR5FiDAdb
66
+ QKz1q5bgs3bb2pLpERNF+z13OS10Mzk1zdr++1pov5PWOTBRKmvBtPJKswmDpb0y
67
+ jQGeeqBFZwKzx0n6BTzDZtkqzTwvGhbm9Sb+qO0IO66IV8zQhPG/JUfDkByd6mX9
68
+ Ykke0gxoRx54XqoRwZGNydOxMN6g3Oj1+ioWisltYLs/SzW20f3AMCoTeYyfjKtf
69
+ 01refrA3aRfhDctvW5/s2LP0OEG2P/yQYXiGhK6uVxShz3Oa5dhFwiS8G63omZRH
70
+ AEqSk46EhAbbT4xfZ/Np209rhis4KW40cMMpI0F+XpyfT05ZQD6ytHTPgWTxv/OF
71
+ G9zy2ysT0kq+t+Hb+1RWQUq/2Dz9Lf6xLZPgqtyzg8xiFxZ4i1kf/VDWa3M76zn3
72
+ qMcj3SPOxKY//wW70jCxf44yD38NvSa1M2Sz/K/RJKWkRWP/jhV1UHYusbzCmsvm
73
+ M9JkknNMJvGIjBDjHEVy6dlTaHQoHDY+Me9gsrEX0ZS9xXgAiB2IupabEwARAQAB
74
+ tEJGcmVlUkRQIFNlY3VyaXR5IFRlYW0gKGh0dHBzOi8vZnJlZXJkcC5jb20pIDxz
75
+ ZWN1cml0eUBmcmVlcmRwLmNvbT6JAk4EEwEKADgWIQRvuAE0sDt7JnxXu0o3Ibww
76
+ YbfjNAUCYHP6OwIbAwULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRA3IbwwYbfj
77
+ NPviD/43NLg7YfjAlvj5GipSmgelLwlIA+L/qbrf4NAB+NZ9oqp3bBdj4e5gZmiI
78
+ zd6bkANCqk21YiOE31medUfy+nfBQFVvj0oUg1X16C6RaIX5qA3Dwt5qBwKmDkT5
79
+ j7JlxUS6Eluiau67ePiDYu2Wbp0qYuAmNUNL+Y2NCO9UJiy0Oq6YVXS971D5lC+a
80
+ SX0x9pizmFV3zro+l6/3kHTVbPednfX99yz9SZge64aWXo3MXVN8JD0lR3+92l99
81
+ XsFDc+lGeR4azLFIqXC4Cr5Lbk34Hw/VwUC32xxFUaJ2ZmV3pA8bhCtBSxSmxnHS
82
+ H3hoBaD1WpuApbW8Psx6qsgoaSUdWsjluA4eQ5afJBf9O2NlT1mim5MAINY4PbWP
83
+ o4zq3p1ABVTzuB8tsGA9o6DeYVUUrj7lCv9STdGRhm0472BDkp/gvKMBoPgg3Qez
84
+ kvGKK7iVy8R/BOPjh9wP1art5JLVsralXGHA/5Ceid4ojKFzGIC9g3lnAPh+T/eM
85
+ duyY9XH4un1r73r6DRqUoczSfHYbxhKxWt0cRNdIadcXXusMPV/w4J4j55WcLrBE
86
+ 5nopp/prJ5bYegUvRRrwVSFwLDxkE2dh68Zvlh5VWXIPFge0RPEAijYWR5qR2z+/
87
+ VHgPYmliOnWFJN1rzekmWjKFtg5A57FkZyk3cp5x0/2xAX+TIbkCDQRgc/o7ARAA
88
+ vw53CoVkMzBlisSEETNdEKQMaiQ8BtbC438v/b1mOOeoE0YCfSW7RyflA/TXHOah
89
+ db0s3v/Kk2xmbjeMS9IJXlWviKKnOVMrMZvtJdQ4EKfqc5EpxNx7OiEofA/7n7Xs
90
+ 1YEt6KjYaM/vgANl9HA2UXzqSFiRhkWjj1WA7vhqCWUArpAMGeCDYab2BBfp6Z4f
91
+ W9178N2vHH+Hh/uBwGUDnShU38GH8Nstkdcyw5puiJqNQBfZ1Fz9luzutp6zAgHz
92
+ WzobeRPZCCXs7CfxcvpkFS0ctOteQtIRIfP+jbDnldMmClQ87UVcKv0pCCJkMLNk
93
+ YUCMAb2UC2boCIf0omeeque4+FOphcO4+R/8jc6cYlQpgwUg2/IwBEEnCqtvo3qu
94
+ k6uzONhfWZPtUdJd158MGKGTogXVXGzoGzxIrKkZ4W1VuuMiEmhIQZO8e7/4Iz4a
95
+ Zp4qQXI8rsmNJN3lB5a7MWgrZ8mjllYRdfiTEvfQ+PiQqnG6PEHZ82om9kp555gs
96
+ 15UqhjHAqRRtfXzQvZko0ngAxxZNVFPwK8LnxkyEPClRBC5eV3ljI8cvCfnWD01q
97
+ rCzSlSafFHCEUEQOhOrf/bBbXPkYTJw2KlumH5w9R6xQWgqneiD/+Qmqdclzdn36
98
+ Pgbhyu6uSNZehbx5ptt/EM66JSAW7Q7W6Qnz5PNnHgEAEQEAAYkCNgQYAQoAIBYh
99
+ BG+4ATSwO3smfFe7SjchvDBht+M0BQJgc/o7AhsMAAoJEDchvDBht+M0JYUQALlV
100
+ dwmk6ZFq5dq0utWgutysL47b30BhYwNMVe0/6UW4h4TYaW6B3f58X7ik7EdYciyR
101
+ 68eYfwKGhuv/y90QaGXJMU13XHpoInSaHQRhn5M/GkN16DBXdBok70Fh9Gx89Zhs
102
+ VKF3qwIVx5AO5CwrVA6F/iOiUEW31xiT7VFkbW1Cfl5H+M6nVXSR1bOdmxTObTz7
103
+ CEeJMOVrZs36hVLMWLqZF0igVebO2AsDOY63fy/9MLn8ynCHhnAMvsm9ULWuFzGj
104
+ OsJezChduaHqPkopgwihe7jthUn4qWjABbbzKkS6HLBpGAfCzUun+lMpvIEUf+EJ
105
+ bpk7gj9xDEP6y96tV/dCeWb4p8N8webR8nVgsRxoEnfIdCkoB80iZGOzKfYYnvdz
106
+ ngs8MIL6dC4Nc1/t9ECV4O/w4uwIH65nC1ay0YOK/O/j2SEfnVHQmAuOsgTz+pBn
107
+ u6DIA2HsBzFdOCljtf3m4AeAaTbL7MBSDceApqg0lcrhjclqHJo1aJh3M6aVm3gq
108
+ yUt7y26Hkh/vYEJwW4gqRho4gb7BvjTZh5LUbrjmRtexFQ1eWM82u23yYS2L+y2Y
109
+ ejSKIKmJhXHqsgCVGYw5woZEEMzgpkoIWYG/Eoy+oVuU02QITh/Uc5VRsA9DuwSV
110
+ Vw2F8gu/fHiadawxWIhUH+plFVQZc1KwgPcIMW3S
111
+ =O0kP
112
+ -----END PGP PUBLIC KEY BLOCK-----
113
+ ```
114
+ [^1]: https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing/privately-reporting-a-security-vulnerability
local-test-freerdp-delta-01/afc-freerdp/channels/CMakeLists.txt ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FreeRDP: A Remote Desktop Protocol Implementation
2
+ # FreeRDP cmake build script
3
+ #
4
+ # Copyright 2012 Marc-Andre Moreau <[email protected]>
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ include(CMakeParseArguments)
19
+ include(CMakeDependentOption)
20
+
21
+ macro(define_channel_options)
22
+ set(PREFIX "CHANNEL")
23
+
24
+ cmake_parse_arguments(
25
+ ${PREFIX} "" "NAME;TYPE;DESCRIPTION;SPECIFICATIONS;DEFAULT;CLIENT_DEFAULT;SERVER_DEFAULT" "" ${ARGN}
26
+ )
27
+
28
+ string(TOUPPER "CHANNEL_${CHANNEL_NAME}" CHANNEL_OPTION)
29
+ string(TOUPPER "CHANNEL_${CHANNEL_NAME}_CLIENT" CHANNEL_CLIENT_OPTION)
30
+ string(TOUPPER "CHANNEL_${CHANNEL_NAME}_SERVER" CHANNEL_SERVER_OPTION)
31
+ string(TOUPPER "${CHANNEL_TYPE}" CHANNEL_TYPE)
32
+
33
+ if(CHANNEL_DEFAULT)
34
+ set(OPTION_DEFAULT ${CHANNEL_DEFAULT})
35
+ elseif(CHANNEL_CLIENT_OPTION OR CHANNEL_SERVER_OPTION)
36
+ set(OPTION_DEFAULT "ON")
37
+ endif()
38
+
39
+ set(CHANNEL_OPTION_DOC "Build ${CHANNEL_NAME} ${CHANNEL_TYPE} channel")
40
+ set(CHANNEL_CLIENT_OPTION_DOC "Build ${CHANNEL_NAME} ${CHANNEL_TYPE} channel client")
41
+ set(CHANNEL_SERVER_OPTION_DOC "Build ${CHANNEL_NAME} ${CHANNEL_TYPE} channel server")
42
+
43
+ if("${CHANNEL_TYPE}" STREQUAL "DYNAMIC")
44
+ cmake_dependent_option(${CHANNEL_OPTION} "${CHANNEL_OPTION_DOC}" ${CHANNEL_DEFAULT} "CHANNEL_DRDYNVC" OFF)
45
+ else()
46
+ option(${CHANNEL_OPTION} "${CHANNEL_OPTION_DOC}" ${CHANNEL_DEFAULT})
47
+ endif()
48
+
49
+ cmake_dependent_option(
50
+ ${CHANNEL_CLIENT_OPTION} "${CHANNEL_CLIENT_OPTION_DOC}" ${CHANNEL_CLIENT_DEFAULT} "${CHANNEL_OPTION}" OFF
51
+ )
52
+
53
+ cmake_dependent_option(
54
+ ${CHANNEL_SERVER_OPTION} "${CHANNEL_SERVER_OPTION_DOC}" ${CHANNEL_SERVER_DEFAULT} "${CHANNEL_OPTION}" OFF
55
+ )
56
+ endmacro(define_channel_options)
57
+
58
+ macro(define_channel _channel_name)
59
+ set(CHANNEL_NAME ${_channel_name})
60
+ set(MODULE_NAME ${CHANNEL_NAME})
61
+ string(TOUPPER "CHANNEL_${CHANNEL_NAME}" MODULE_PREFIX)
62
+ endmacro(define_channel)
63
+
64
+ macro(define_channel_client _channel_name)
65
+ set(CHANNEL_NAME ${_channel_name})
66
+ set(MODULE_NAME "${CHANNEL_NAME}-client")
67
+ string(TOUPPER "CHANNEL_${CHANNEL_NAME}_CLIENT" MODULE_PREFIX)
68
+ endmacro(define_channel_client)
69
+
70
+ macro(define_channel_server _channel_name)
71
+ set(CHANNEL_NAME ${_channel_name})
72
+ set(MODULE_NAME "${CHANNEL_NAME}-server")
73
+ string(TOUPPER "CHANNEL_${CHANNEL_NAME}_SERVER" MODULE_PREFIX)
74
+ endmacro(define_channel_server)
75
+
76
+ macro(define_channel_client_subsystem _channel_name _subsystem _type)
77
+ set(CHANNEL_NAME ${_channel_name})
78
+ set(CHANNEL_SUBSYSTEM ${_subsystem})
79
+ string(LENGTH "${_type}" _type_length)
80
+ string(TOUPPER "CHANNEL_${CHANNEL_NAME}_CLIENT" CHANNEL_PREFIX)
81
+ if(_type_length GREATER 0)
82
+ set(SUBSYSTEM_TYPE ${_type})
83
+ set(MODULE_NAME "${CHANNEL_NAME}-client-${CHANNEL_SUBSYSTEM}-${SUBSYSTEM_TYPE}")
84
+ string(TOUPPER "CHANNEL_${CHANNEL_NAME}_CLIENT_${CHANNEL_SUBSYSTEM}_${SUBSYSTEM_TYPE}" MODULE_PREFIX)
85
+ else()
86
+ set(MODULE_NAME "${CHANNEL_NAME}-client-${CHANNEL_SUBSYSTEM}")
87
+ string(TOUPPER "CHANNEL_${CHANNEL_NAME}_CLIENT_${CHANNEL_SUBSYSTEM}" MODULE_PREFIX)
88
+ endif()
89
+ endmacro(define_channel_client_subsystem)
90
+
91
+ macro(define_channel_server_subsystem _channel_name _subsystem _type)
92
+ set(CHANNEL_NAME ${_channel_name})
93
+ set(CHANNEL_SUBSYSTEM ${_subsystem})
94
+ set(MODULE_NAME "${CHANNEL_NAME}-server-${CHANNEL_SUBSYSTEM}")
95
+ string(TOUPPER "CHANNEL_${CHANNEL_NAME}_server_${CHANNEL_SUBSYSTEM}" MODULE_PREFIX)
96
+ endmacro(define_channel_server_subsystem)
97
+
98
+ macro(add_channel_client _channel_prefix _channel_name)
99
+ if(${_channel_prefix}_CLIENT)
100
+ add_subdirectory(client)
101
+ if(${${_channel_prefix}_CLIENT_STATIC})
102
+ set(CHANNEL_STATIC_CLIENT_MODULES ${CHANNEL_STATIC_CLIENT_MODULES} ${_channel_prefix} PARENT_SCOPE)
103
+ set(${_channel_prefix}_CLIENT_NAME ${${_channel_prefix}_CLIENT_NAME} PARENT_SCOPE)
104
+ set(${_channel_prefix}_CLIENT_CHANNEL ${${_channel_prefix}_CLIENT_CHANNEL} PARENT_SCOPE)
105
+ set(${_channel_prefix}_CLIENT_ENTRY ${${_channel_prefix}_CLIENT_ENTRY} PARENT_SCOPE)
106
+ set(CHANNEL_STATIC_CLIENT_ENTRIES ${CHANNEL_STATIC_CLIENT_ENTRIES} ${${_channel_prefix}_CLIENT_ENTRY}
107
+ PARENT_SCOPE
108
+ )
109
+ endif()
110
+ endif()
111
+ endmacro(add_channel_client)
112
+
113
+ macro(add_channel_server _channel_prefix _channel_name)
114
+ if(${_channel_prefix}_SERVER)
115
+ add_subdirectory(server)
116
+ if(${${_channel_prefix}_SERVER_STATIC})
117
+ set(CHANNEL_STATIC_SERVER_MODULES ${CHANNEL_STATIC_SERVER_MODULES} ${_channel_prefix} PARENT_SCOPE)
118
+ set(${_channel_prefix}_SERVER_NAME ${${_channel_prefix}_SERVER_NAME} PARENT_SCOPE)
119
+ set(${_channel_prefix}_SERVER_CHANNEL ${${_channel_prefix}_SERVER_CHANNEL} PARENT_SCOPE)
120
+ set(${_channel_prefix}_SERVER_ENTRY ${${_channel_prefix}_SERVER_ENTRY} PARENT_SCOPE)
121
+ set(CHANNEL_STATIC_SERVER_ENTRIES ${CHANNEL_STATIC_SERVER_ENTRIES} ${${_channel_prefix}_SERVER_ENTRY}
122
+ PARENT_SCOPE
123
+ )
124
+ endif()
125
+ endif()
126
+ endmacro(add_channel_server)
127
+
128
+ macro(add_channel_client_subsystem _channel_prefix _channel_name _subsystem _type)
129
+ add_subdirectory(${_subsystem})
130
+ set(_channel_module_name "${_channel_name}-client")
131
+ string(LENGTH "${_type}" _type_length)
132
+ if(_type_length GREATER 0)
133
+ string(TOUPPER "CHANNEL_${_channel_name}_CLIENT_${_subsystem}_${_type}" _subsystem_prefix)
134
+ else()
135
+ string(TOUPPER "CHANNEL_${_channel_name}_CLIENT_${_subsystem}" _subsystem_prefix)
136
+ endif()
137
+ if(${${_subsystem_prefix}_STATIC})
138
+ get_target_property(CHANNEL_SUBSYSTEMS ${_channel_module_name} SUBSYSTEMS)
139
+ if(_type_length GREATER 0)
140
+ set(SUBSYSTEMS ${SUBSYSTEMS} "${_subsystem}-${_type}")
141
+ else()
142
+ set(SUBSYSTEMS ${SUBSYSTEMS} ${_subsystem})
143
+ endif()
144
+ set_target_properties(${_channel_module_name} PROPERTIES SUBSYSTEMS "${SUBSYSTEMS}")
145
+ endif()
146
+ endmacro(add_channel_client_subsystem)
147
+
148
+ macro(channel_install _targets _destination _export_target)
149
+ if(NOT BUILD_SHARED_LIBS)
150
+ foreach(_target_name IN ITEMS ${_targets})
151
+ target_include_directories(${_target_name} INTERFACE $<INSTALL_INTERFACE:include>)
152
+ endforeach()
153
+ install(TARGETS ${_targets} DESTINATION ${_destination} EXPORT ${_export_target})
154
+ endif()
155
+ endmacro(channel_install)
156
+
157
+ macro(server_channel_install _targets _destination)
158
+ channel_install(${_targets} ${_destination} "FreeRDP-ServerTargets")
159
+ endmacro(server_channel_install)
160
+
161
+ macro(client_channel_install _targets _destination)
162
+ channel_install(${_targets} ${_destination} "FreeRDP-ClientTargets")
163
+ endmacro(client_channel_install)
164
+
165
+ macro(add_channel_client_library _module_prefix _module_name _channel_name _dynamic _entry)
166
+ set(_lnk_dir ${${_module_prefix}_LINK_DIRS})
167
+ if(NOT "${_lnk_dir}" STREQUAL "")
168
+ link_directories(${_lnk_dir})
169
+ endif()
170
+
171
+ set(${_module_prefix}_STATIC ON PARENT_SCOPE)
172
+ set(${_module_prefix}_NAME ${_module_name} PARENT_SCOPE)
173
+ set(${_module_prefix}_CHANNEL ${_channel_name} PARENT_SCOPE)
174
+ set(${_module_prefix}_ENTRY ${_entry} PARENT_SCOPE)
175
+
176
+ add_library(${_module_name} OBJECT ${${_module_prefix}_SRCS})
177
+ set_property(TARGET ${_module_name} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client")
178
+
179
+ if(${_module_prefix}_LIBS)
180
+ target_link_libraries(${_module_name} PUBLIC ${${_module_prefix}_LIBS})
181
+ endif()
182
+ client_channel_install(${_module_name} ${FREERDP_ADDIN_PATH})
183
+ endmacro(add_channel_client_library)
184
+
185
+ macro(
186
+ add_channel_client_subsystem_library
187
+ _module_prefix
188
+ _module_name
189
+ _channel_name
190
+ _type
191
+ _dynamic
192
+ _entry
193
+ )
194
+ set(_lnk_dir ${${_module_prefix}_LINK_DIRS})
195
+ if(NOT "${_lnk_dir}" STREQUAL "")
196
+ link_directories(${_lnk_dir})
197
+ endif()
198
+
199
+ set(${_module_prefix}_STATIC ON PARENT_SCOPE)
200
+ set(${_module_prefix}_NAME ${_module_name} PARENT_SCOPE)
201
+ set(${_module_prefix}_TYPE ${_type} PARENT_SCOPE)
202
+
203
+ add_library(${_module_name} OBJECT ${${_module_prefix}_SRCS})
204
+ set_property(TARGET ${_module_name} PROPERTY FOLDER "Channels/${_channel_name}/Client/Subsystem/${CHANNEL_SUBSYSTEM}")
205
+
206
+ if(${_module_prefix}_LIBS)
207
+ target_link_libraries(${_module_name} PUBLIC ${${_module_prefix}_LIBS})
208
+ endif()
209
+ client_channel_install(${_module_name} ${FREERDP_ADDIN_PATH})
210
+ endmacro(add_channel_client_subsystem_library)
211
+
212
+ macro(add_channel_server_library _module_prefix _module_name _channel_name _dynamic _entry)
213
+ set(_lnk_dir ${${_module_prefix}_LINK_DIRS})
214
+ if(NOT "${_lnk_dir}" STREQUAL "")
215
+ link_directories(${_lnk_dir})
216
+ endif()
217
+
218
+ set(${_module_prefix}_STATIC ON PARENT_SCOPE)
219
+ set(${_module_prefix}_NAME ${_module_name} PARENT_SCOPE)
220
+ set(${_module_prefix}_CHANNEL ${_channel_name} PARENT_SCOPE)
221
+ set(${_module_prefix}_ENTRY ${_entry} PARENT_SCOPE)
222
+
223
+ add_library(${_module_name} OBJECT ${${_module_prefix}_SRCS})
224
+ set_property(TARGET ${_module_name} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Server")
225
+
226
+ if(${_module_prefix}_LIBS)
227
+ target_link_libraries(${_module_name} PUBLIC ${${_module_prefix}_LIBS})
228
+ endif()
229
+ server_channel_install(${_module_name} ${FREERDP_ADDIN_PATH})
230
+ endmacro(add_channel_server_library)
231
+
232
+ set(FILENAME "ChannelOptions.cmake")
233
+ file(GLOB FILEPATHS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*/${FILENAME}")
234
+
235
+ # We need special treatment for drdynvc:
236
+ # It needs to be the first entry so that every
237
+ # dynamic channel has the dependent options available.
238
+ set(DRDYNVC_MATCH "")
239
+
240
+ foreach(FILEPATH ${FILEPATHS})
241
+ if(${FILEPATH} MATCHES "^([^/]*)drdynvc/+${FILENAME}")
242
+ set(DRDYNVC_MATCH ${FILEPATH})
243
+ endif()
244
+ endforeach()
245
+
246
+ if(NOT "${DRDYNVC_MATCH}" STREQUAL "")
247
+ list(REMOVE_ITEM FILEPATHS ${DRDYNVC_MATCH})
248
+ list(APPEND FILEPATHS ${DRDYNVC_MATCH})
249
+ list(REVERSE FILEPATHS) # list PREPEND is not available on old CMake3
250
+ endif()
251
+
252
+ foreach(FILEPATH ${FILEPATHS})
253
+ if(${FILEPATH} MATCHES "^([^/]*)/+${FILENAME}")
254
+ string(REGEX REPLACE "^([^/]*)/+${FILENAME}" "\\1" DIR ${FILEPATH})
255
+ set(CHANNEL_OPTION)
256
+ include(${FILEPATH})
257
+ if(${CHANNEL_OPTION})
258
+ set(CHANNEL_MESSAGE "Adding ${CHANNEL_TYPE} channel")
259
+ if(${CHANNEL_CLIENT_OPTION})
260
+ set(CHANNEL_MESSAGE "${CHANNEL_MESSAGE} client")
261
+ endif()
262
+ if(${CHANNEL_SERVER_OPTION})
263
+ set(CHANNEL_MESSAGE "${CHANNEL_MESSAGE} server")
264
+ endif()
265
+ set(CHANNEL_MESSAGE "${CHANNEL_MESSAGE} \"${CHANNEL_NAME}\"")
266
+ set(CHANNEL_MESSAGE "${CHANNEL_MESSAGE}: ${CHANNEL_DESCRIPTION}")
267
+ message(STATUS "${CHANNEL_MESSAGE}")
268
+ add_subdirectory(${DIR})
269
+ endif()
270
+ endif()
271
+ endforeach(FILEPATH)
272
+
273
+ if(WITH_CHANNELS)
274
+ if(WITH_CLIENT_CHANNELS)
275
+ add_subdirectory(client)
276
+ set(FREERDP_CHANNELS_CLIENT_SRCS ${FREERDP_CHANNELS_CLIENT_SRCS} PARENT_SCOPE)
277
+ set(FREERDP_CHANNELS_CLIENT_LIBS ${FREERDP_CHANNELS_CLIENT_LIBS} PARENT_SCOPE)
278
+ endif()
279
+
280
+ if(WITH_SERVER_CHANNELS)
281
+ add_subdirectory(server)
282
+ set(FREERDP_CHANNELS_SERVER_SRCS ${FREERDP_CHANNELS_SERVER_SRCS} PARENT_SCOPE)
283
+ set(FREERDP_CHANNELS_SERVER_LIBS ${FREERDP_CHANNELS_SERVER_LIBS} PARENT_SCOPE)
284
+ endif()
285
+ endif()
local-test-freerdp-delta-01/afc-freerdp/client/CMakeLists.txt ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FreeRDP: A Remote Desktop Protocol Implementation
2
+ # FreeRDP Clients
3
+ #
4
+ # Copyright 2012 Marc-Andre Moreau <[email protected]>
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ # Clients
19
+
20
+ include(CMakeDependentOption)
21
+ include(InstallFreeRDPDesktop)
22
+
23
+ if(WITH_CLIENT_COMMON)
24
+ add_subdirectory(common)
25
+ endif()
26
+
27
+ if(FREERDP_VENDOR AND WITH_CLIENT)
28
+ if(WIN32 AND NOT UWP)
29
+ add_subdirectory(Windows)
30
+ else()
31
+ if(WITH_SAMPLE)
32
+ add_subdirectory(Sample)
33
+ endif()
34
+ endif()
35
+
36
+ if(WITH_CLIENT_SDL)
37
+ add_subdirectory(SDL)
38
+ endif()
39
+
40
+ if(WITH_X11)
41
+ add_subdirectory(X11)
42
+ endif()
43
+
44
+ if(WITH_WAYLAND AND WAYLAND_FOUND)
45
+ add_subdirectory(Wayland)
46
+ endif()
47
+
48
+ if(APPLE)
49
+ if(IOS)
50
+ if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/iOS")
51
+ message(STATUS "Adding iOS client")
52
+ add_subdirectory(iOS)
53
+ endif()
54
+ else()
55
+ option(WITH_CLIENT_MAC "Build native mac client" ON)
56
+ if(WITH_CLIENT_MAC)
57
+ add_subdirectory(Mac)
58
+ endif()
59
+ endif()
60
+ endif()
61
+
62
+ if(ANDROID)
63
+ message(STATUS "Android client module is built with Android Studio project")
64
+ endif()
65
+ endif()
66
+
67
+ # Pick up other clients
68
+ if(WITH_CLIENT)
69
+ set(FILENAME "ModuleOptions.cmake")
70
+ file(GLOB FILEPATHS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*/${FILENAME}")
71
+
72
+ foreach(FILEPATH ${FILEPATHS})
73
+ if(${FILEPATH} MATCHES "^([^/]*)/+${FILENAME}")
74
+ string(REGEX REPLACE "^([^/]*)/+${FILENAME}" "\\1" FREERDP_CLIENT ${FILEPATH})
75
+ set(FREERDP_CLIENT_ENABLED 0)
76
+ include(${FILEPATH})
77
+ if(FREERDP_CLIENT_ENABLED)
78
+ if(NOT (${FREERDP_CLIENT_VENDOR} MATCHES "FreeRDP"))
79
+ list(APPEND FREERDP_EXTRA_CLIENTS ${FREERDP_CLIENT})
80
+ if(${FREERDP_CLIENT_VENDOR} MATCHES "${VENDOR}")
81
+ set(CLIENT_VENDOR_PATH "client/${FREERDP_CLIENT}" PARENT_SCOPE)
82
+ endif()
83
+ endif()
84
+ endif()
85
+ endif()
86
+ endforeach()
87
+
88
+ foreach(FREERDP_CLIENT ${FREERDP_EXTRA_CLIENTS})
89
+ add_subdirectory(${FREERDP_CLIENT})
90
+ endforeach()
91
+ endif()
92
+
93
+ if(WITH_FUSE)
94
+ list(APPEND FREERDP_CLIENT_PC_PRIVATE_LIBS "-lfuse3")
95
+ endif()
96
+
97
+ list(JOIN FREERDP_CLIENT_PC_PRIVATE_LIBS " " FREERDP_CLIENT_PC_PRIVATE_LIBS)
98
+ include(pkg-config-install-prefix)
99
+ cleaning_configure_file(
100
+ ${CMAKE_CURRENT_SOURCE_DIR}/freerdp-client.pc.in
101
+ ${CMAKE_CURRENT_BINARY_DIR}/freerdp-client${FREERDP_VERSION_MAJOR}.pc @ONLY
102
+ )
103
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp-client${FREERDP_VERSION_MAJOR}.pc
104
+ DESTINATION ${PKG_CONFIG_PC_INSTALL_DIR}
105
+ )
106
+
107
+ export(PACKAGE freerdp-client)
108
+
109
+ setfreerdpcmakeinstalldir(FREERDP_CLIENT_CMAKE_INSTALL_DIR "FreeRDP-Client${FREERDP_VERSION_MAJOR}")
110
+
111
+ configure_package_config_file(
112
+ FreeRDP-ClientConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FreeRDP-ClientConfig.cmake
113
+ INSTALL_DESTINATION ${FREERDP_CLIENT_CMAKE_INSTALL_DIR} PATH_VARS FREERDP_INCLUDE_DIR
114
+ )
115
+
116
+ write_basic_package_version_file(
117
+ ${CMAKE_CURRENT_BINARY_DIR}/FreeRDP-ClientConfigVersion.cmake VERSION ${FREERDP_VERSION}
118
+ COMPATIBILITY SameMajorVersion
119
+ )
120
+
121
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FreeRDP-ClientConfig.cmake
122
+ ${CMAKE_CURRENT_BINARY_DIR}/FreeRDP-ClientConfigVersion.cmake
123
+ DESTINATION ${FREERDP_CLIENT_CMAKE_INSTALL_DIR}
124
+ )
125
+
126
+ install(EXPORT FreeRDP-ClientTargets DESTINATION ${FREERDP_CLIENT_CMAKE_INSTALL_DIR})
local-test-freerdp-delta-01/afc-freerdp/client/FreeRDP-ClientConfig.cmake.in ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ include(CMakeFindDependencyMacro)
2
+ find_dependency(WinPR @FREERDP_VERSION@)
3
+ find_dependency(FreeRDP @FREERDP_VERSION@)
4
+ if("@WITH_SMARTCARD_EMULATE@")
5
+ find_dependency(ZLIB)
6
+ endif()
7
+
8
+ @PACKAGE_INIT@
9
+
10
+ set(FreeRDP-Client_VERSION_MAJOR "@FREERDP_VERSION_MAJOR@")
11
+ set(FreeRDP-Client_VERSION_MINOR "@FREERDP_VERSION_MINOR@")
12
+ set(FreeRDP-Client_VERSION_REVISION "@FREERDP_VERSION_REVISION@")
13
+
14
+ set_and_check(FreeRDP-Client_INCLUDE_DIR "@PACKAGE_FREERDP_INCLUDE_DIR@")
15
+
16
+ include("${CMAKE_CURRENT_LIST_DIR}/FreeRDP-ClientTargets.cmake")
local-test-freerdp-delta-01/afc-freerdp/client/SDL/CMakeLists.txt ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FreeRDP: A Remote Desktop Protocol Implementation
2
+ # FreeRDP SDL Client
3
+ #
4
+ # Copyright 2024 Armin Novak <[email protected]>
5
+ # Copyright 2024 Thincast Technologies GmbH
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ cmake_minimum_required(VERSION 3.13)
19
+
20
+ if(POLICY CMP0091)
21
+ cmake_policy(SET CMP0091 NEW)
22
+ endif()
23
+ if(NOT FREERDP_DEFAULT_PROJECT_VERSION)
24
+ set(FREERDP_DEFAULT_PROJECT_VERSION "1.0.0.0")
25
+ endif()
26
+
27
+ project(sdl-freerdp LANGUAGES CXX VERSION ${FREERDP_DEFAULT_PROJECT_VERSION})
28
+
29
+ message("project ${PROJECT_NAME} is using version ${PROJECT_VERSION}")
30
+
31
+ set(CMAKE_CXX_STANDARD 17)
32
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
33
+ set(CMAKE_CXX_EXTENSIONS ON)
34
+
35
+ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/)
36
+ include(CommonConfigOptions)
37
+
38
+ include(ConfigureFreeRDP)
39
+ include(CXXCompilerFlags)
40
+
41
+ option(WITH_DEBUG_SDL_EVENTS "[dangerous, not for release builds!] Debug SDL events" ${DEFAULT_DEBUG_OPTION})
42
+ option(WITH_DEBUG_SDL_KBD_EVENTS "[dangerous, not for release builds!] Debug SDL keyboard events"
43
+ ${DEFAULT_DEBUG_OPTION}
44
+ )
45
+ option(WITH_WIN_CONSOLE "Build ${PROJECT_NAME} with console support" ON)
46
+ option(WITH_SDL_LINK_SHARED "link SDL dynamic or static" ON)
47
+
48
+ if(WITH_WIN_CONSOLE)
49
+ set(WIN32_GUI_FLAG "TRUE")
50
+ else()
51
+ set(WIN32_GUI_FLAG "WIN32")
52
+ endif()
53
+
54
+ if(WITH_DEBUG_SDL_EVENTS)
55
+ add_compile_definitions(WITH_DEBUG_SDL_EVENTS)
56
+ endif()
57
+ if(WITH_DEBUG_SDL_KBD_EVENTS)
58
+ add_compile_definitions(WITH_DEBUG_SDL_KBD_EVENTS)
59
+ endif()
60
+
61
+ include(CMakeDependentOption)
62
+
63
+ # Require 2.0.20 for ubuntu 22.04.
64
+ # older versions do not have the SDL2::SDL2 et al targets
65
+ find_package(SDL2 2.0.20)
66
+ find_package(SDL3)
67
+
68
+ cmake_dependent_option(WITH_CLIENT_SDL_VERSIONED "append sdl version to client binaries" OFF WITH_CLIENT_SDL OFF)
69
+ cmake_dependent_option(
70
+ WITH_CLIENT_SDL2 "[experimental] build experimental SDL2 client" ${SDL2_FOUND} WITH_CLIENT_SDL OFF
71
+ )
72
+ cmake_dependent_option(
73
+ WITH_CLIENT_SDL3 "[experimental] build experimental SDL3 client" ${SDL3_FOUND} WITH_CLIENT_SDL OFF
74
+ )
75
+
76
+ if(WITH_CLIENT_SDL2 AND WITH_CLIENT_SDL3)
77
+ message("Building both, SDL2 and SDL3 clients, forcing WITH_CLIENT_SDL_VERSIONED=ON")
78
+ set(WITH_CLIENT_SDL_VERSIONED ON)
79
+ endif()
80
+
81
+ if(NOT SDL2_FOUND AND NOT SDL3_FOUND)
82
+ message(WARNING "No SDL library detected, giving up. Install SDL2 or SDL3 development package to fix")
83
+ endif()
84
+
85
+ if((WITH_CLIENT_SDL2 AND SDL2_FOUND) OR (WITH_CLIENT_SDL3 AND SDL3_FOUND))
86
+ add_subdirectory(common)
87
+ include_directories(common)
88
+ endif()
89
+
90
+ if(WITH_CLIENT_SDL2)
91
+ if(SDL2_FOUND)
92
+ add_subdirectory(SDL2)
93
+ else()
94
+ message(WARNING "SDL2 requested but not found, continuing build without SDL2 client")
95
+ endif()
96
+ endif()
97
+
98
+ if(WITH_CLIENT_SDL3)
99
+ if(SDL3_FOUND)
100
+ add_subdirectory(SDL3)
101
+ else()
102
+ message(WARNING "SDL3 requested but not found, continuing build without SDL3 client")
103
+ endif()
104
+ endif()
local-test-freerdp-delta-01/afc-freerdp/client/Sample/CMakeLists.txt ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FreeRDP: A Remote Desktop Protocol Implementation
2
+ # FreeRDP Sample UI cmake build script
3
+ #
4
+ # Copyright 2012 Marc-Andre Moreau <[email protected]>
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ cmake_minimum_required(VERSION 3.13)
18
+
19
+ if(POLICY CMP0091)
20
+ cmake_policy(SET CMP0091 NEW)
21
+ endif()
22
+ if(NOT FREERDP_DEFAULT_PROJECT_VERSION)
23
+ set(FREERDP_DEFAULT_PROJECT_VERSION "1.0.0.0")
24
+ endif()
25
+
26
+ project(sfreerdp LANGUAGES C VERSION ${FREERDP_DEFAULT_PROJECT_VERSION})
27
+
28
+ message("project ${PROJECT_NAME} is using version ${PROJECT_VERSION}")
29
+
30
+ set(CMAKE_C_STANDARD 11)
31
+ set(CMAKE_C_STANDARD_REQUIRED ON)
32
+ set(CMAKE_C_EXTENSIONS ON)
33
+
34
+ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/)
35
+ include(CommonConfigOptions)
36
+
37
+ include(ConfigureFreeRDP)
38
+
39
+ set(SRCS tf_channels.c tf_channels.h tf_freerdp.h tf_freerdp.c)
40
+
41
+ addtargetwithresourcefile(${PROJECT_NAME} TRUE "${PROJECT_VERSION}" SRCS)
42
+
43
+ set(LIBS freerdp-client freerdp winpr)
44
+ target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBS})
45
+
46
+ set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Client/Sample")
47
+ install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT client)
48
+ install_freerdp_desktop("${PROJECT_NAME}")
local-test-freerdp-delta-01/afc-freerdp/client/Sample/ModuleOptions.cmake ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ set(FREERDP_CLIENT_NAME "sfreerdp")
2
+ set(FREERDP_CLIENT_PLATFORM "Sample")
3
+ set(FREERDP_CLIENT_VENDOR "FreeRDP")
local-test-freerdp-delta-01/afc-freerdp/client/Sample/tf_channels.c ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Sample Client Channels
4
+ *
5
+ * Copyright 2018 Armin Novak <[email protected]>
6
+ * Copyright 2018 Thincast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #include <freerdp/config.h>
22
+
23
+ #include <winpr/assert.h>
24
+ #include <freerdp/gdi/gfx.h>
25
+
26
+ #include <freerdp/client/rdpei.h>
27
+ #include <freerdp/client/rail.h>
28
+ #include <freerdp/client/cliprdr.h>
29
+ #include <freerdp/client/rdpgfx.h>
30
+ #include <freerdp/client/encomsp.h>
31
+
32
+ #include "tf_channels.h"
33
+ #include "tf_freerdp.h"
34
+
35
+ void tf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e)
36
+ {
37
+ tfContext* tf = (tfContext*)context;
38
+
39
+ WINPR_ASSERT(tf);
40
+ WINPR_ASSERT(e);
41
+
42
+ if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0)
43
+ {
44
+ }
45
+ else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
46
+ {
47
+ CliprdrClientContext* clip = (CliprdrClientContext*)e->pInterface;
48
+ WINPR_ASSERT(clip);
49
+ clip->custom = context;
50
+ }
51
+ else
52
+ freerdp_client_OnChannelConnectedEventHandler(&tf->common, e);
53
+ }
54
+
55
+ void tf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e)
56
+ {
57
+ tfContext* tf = (tfContext*)context;
58
+
59
+ WINPR_ASSERT(tf);
60
+ WINPR_ASSERT(e);
61
+
62
+ if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0)
63
+ {
64
+ }
65
+ else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
66
+ {
67
+ CliprdrClientContext* clip = (CliprdrClientContext*)e->pInterface;
68
+ WINPR_ASSERT(clip);
69
+ clip->custom = NULL;
70
+ }
71
+ else
72
+ freerdp_client_OnChannelDisconnectedEventHandler(&tf->common, e);
73
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Sample/tf_channels.h ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Sample Client Channels
4
+ *
5
+ * Copyright 2018 Armin Novak <[email protected]>
6
+ * Copyright 2018 Thincast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #ifndef FREERDP_CLIENT_SAMPLE_CHANNELS_H
22
+ #define FREERDP_CLIENT_SAMPLE_CHANNELS_H
23
+
24
+ #include <freerdp/freerdp.h>
25
+ #include <freerdp/client/channels.h>
26
+
27
+ int tf_on_channel_connected(freerdp* instance, const char* name, void* pInterface);
28
+ int tf_on_channel_disconnected(freerdp* instance, const char* name, void* pInterface);
29
+
30
+ void tf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e);
31
+ void tf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e);
32
+
33
+ #endif /* FREERDP_CLIENT_SAMPLE_CHANNELS_H */
local-test-freerdp-delta-01/afc-freerdp/client/Sample/tf_freerdp.c ADDED
@@ -0,0 +1,417 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP Test UI
4
+ *
5
+ * Copyright 2011 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2016,2018 Armin Novak <[email protected]>
7
+ * Copyright 2016,2018 Thincast Technologies GmbH
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+
22
+ #include <freerdp/config.h>
23
+
24
+ #include <errno.h>
25
+ #include <stdio.h>
26
+ #include <string.h>
27
+
28
+ #include <freerdp/freerdp.h>
29
+ #include <freerdp/constants.h>
30
+ #include <freerdp/gdi/gdi.h>
31
+ #include <freerdp/streamdump.h>
32
+ #include <freerdp/utils/signal.h>
33
+
34
+ #include <freerdp/client/file.h>
35
+ #include <freerdp/client/cmdline.h>
36
+ #include <freerdp/client/cliprdr.h>
37
+ #include <freerdp/client/channels.h>
38
+ #include <freerdp/channels/channels.h>
39
+
40
+ #include <winpr/crt.h>
41
+ #include <winpr/assert.h>
42
+ #include <winpr/synch.h>
43
+ #include <freerdp/log.h>
44
+
45
+ #include "tf_channels.h"
46
+ #include "tf_freerdp.h"
47
+
48
+ #define TAG CLIENT_TAG("sample")
49
+
50
+ /* This function is called whenever a new frame starts.
51
+ * It can be used to reset invalidated areas. */
52
+ static BOOL tf_begin_paint(rdpContext* context)
53
+ {
54
+ rdpGdi* gdi = NULL;
55
+
56
+ WINPR_ASSERT(context);
57
+
58
+ gdi = context->gdi;
59
+ WINPR_ASSERT(gdi);
60
+ WINPR_ASSERT(gdi->primary);
61
+ WINPR_ASSERT(gdi->primary->hdc);
62
+ WINPR_ASSERT(gdi->primary->hdc->hwnd);
63
+ WINPR_ASSERT(gdi->primary->hdc->hwnd->invalid);
64
+ gdi->primary->hdc->hwnd->invalid->null = TRUE;
65
+ return TRUE;
66
+ }
67
+
68
+ /* This function is called when the library completed composing a new
69
+ * frame. Read out the changed areas and blit them to your output device.
70
+ * The image buffer will have the format specified by gdi_init
71
+ */
72
+ static BOOL tf_end_paint(rdpContext* context)
73
+ {
74
+ rdpGdi* gdi = NULL;
75
+
76
+ WINPR_ASSERT(context);
77
+
78
+ gdi = context->gdi;
79
+ WINPR_ASSERT(gdi);
80
+ WINPR_ASSERT(gdi->primary);
81
+ WINPR_ASSERT(gdi->primary->hdc);
82
+ WINPR_ASSERT(gdi->primary->hdc->hwnd);
83
+ WINPR_ASSERT(gdi->primary->hdc->hwnd->invalid);
84
+
85
+ if (gdi->primary->hdc->hwnd->invalid->null)
86
+ return TRUE;
87
+
88
+ return TRUE;
89
+ }
90
+
91
+ static BOOL tf_desktop_resize(rdpContext* context)
92
+ {
93
+ rdpGdi* gdi = NULL;
94
+ rdpSettings* settings = NULL;
95
+
96
+ WINPR_ASSERT(context);
97
+
98
+ settings = context->settings;
99
+ WINPR_ASSERT(settings);
100
+
101
+ gdi = context->gdi;
102
+ return gdi_resize(gdi, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
103
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
104
+ }
105
+
106
+ /* This function is called to output a System BEEP */
107
+ static BOOL tf_play_sound(rdpContext* context, const PLAY_SOUND_UPDATE* play_sound)
108
+ {
109
+ /* TODO: Implement */
110
+ WINPR_UNUSED(context);
111
+ WINPR_UNUSED(play_sound);
112
+ return TRUE;
113
+ }
114
+
115
+ /* This function is called to update the keyboard indocator LED */
116
+ static BOOL tf_keyboard_set_indicators(rdpContext* context, UINT16 led_flags)
117
+ {
118
+ /* TODO: Set local keyboard indicator LED status */
119
+ WINPR_UNUSED(context);
120
+ WINPR_UNUSED(led_flags);
121
+ return TRUE;
122
+ }
123
+
124
+ /* This function is called to set the IME state */
125
+ static BOOL tf_keyboard_set_ime_status(rdpContext* context, UINT16 imeId, UINT32 imeState,
126
+ UINT32 imeConvMode)
127
+ {
128
+ if (!context)
129
+ return FALSE;
130
+
131
+ WLog_WARN(TAG,
132
+ "KeyboardSetImeStatus(unitId=%04" PRIx16 ", imeState=%08" PRIx32
133
+ ", imeConvMode=%08" PRIx32 ") ignored",
134
+ imeId, imeState, imeConvMode);
135
+ return TRUE;
136
+ }
137
+
138
+ /* Called before a connection is established.
139
+ * Set all configuration options to support and load channels here. */
140
+ static BOOL tf_pre_connect(freerdp* instance)
141
+ {
142
+ rdpSettings* settings = NULL;
143
+
144
+ WINPR_ASSERT(instance);
145
+ WINPR_ASSERT(instance->context);
146
+
147
+ settings = instance->context->settings;
148
+ WINPR_ASSERT(settings);
149
+
150
+ /* If the callbacks provide the PEM all certificate options can be extracted, otherwise
151
+ * only the certificate fingerprint is available. */
152
+ if (!freerdp_settings_set_bool(settings, FreeRDP_CertificateCallbackPreferPEM, TRUE))
153
+ return FALSE;
154
+
155
+ /* Optional OS identifier sent to server */
156
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMajorType, OSMAJORTYPE_UNIX))
157
+ return FALSE;
158
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_NATIVE_XSERVER))
159
+ return FALSE;
160
+ /* OrderSupport is initialized at this point.
161
+ * Only override it if you plan to implement custom order
162
+ * callbacks or deactivate certain features. */
163
+ /* Register the channel listeners.
164
+ * They are required to set up / tear down channels if they are loaded. */
165
+ PubSub_SubscribeChannelConnected(instance->context->pubSub, tf_OnChannelConnectedEventHandler);
166
+ PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
167
+ tf_OnChannelDisconnectedEventHandler);
168
+
169
+ /* TODO: Any code your client requires */
170
+ return TRUE;
171
+ }
172
+
173
+ /* Called after a RDP connection was successfully established.
174
+ * Settings might have changed during negotiation of client / server feature
175
+ * support.
176
+ *
177
+ * Set up local framebuffers and paing callbacks.
178
+ * If required, register pointer callbacks to change the local mouse cursor
179
+ * when hovering over the RDP window
180
+ */
181
+ static BOOL tf_post_connect(freerdp* instance)
182
+ {
183
+ rdpContext* context = NULL;
184
+
185
+ if (!gdi_init(instance, PIXEL_FORMAT_XRGB32))
186
+ return FALSE;
187
+
188
+ context = instance->context;
189
+ WINPR_ASSERT(context);
190
+ WINPR_ASSERT(context->update);
191
+
192
+ /* With this setting we disable all graphics processing in the library.
193
+ *
194
+ * This allows low resource (client) protocol parsing.
195
+ */
196
+ if (!freerdp_settings_set_bool(context->settings, FreeRDP_DeactivateClientDecoding, TRUE))
197
+ return FALSE;
198
+
199
+ context->update->BeginPaint = tf_begin_paint;
200
+ context->update->EndPaint = tf_end_paint;
201
+ context->update->PlaySound = tf_play_sound;
202
+ context->update->DesktopResize = tf_desktop_resize;
203
+ context->update->SetKeyboardIndicators = tf_keyboard_set_indicators;
204
+ context->update->SetKeyboardImeStatus = tf_keyboard_set_ime_status;
205
+ return TRUE;
206
+ }
207
+
208
+ /* This function is called whether a session ends by failure or success.
209
+ * Clean up everything allocated by pre_connect and post_connect.
210
+ */
211
+ static void tf_post_disconnect(freerdp* instance)
212
+ {
213
+ tfContext* context = NULL;
214
+
215
+ if (!instance)
216
+ return;
217
+
218
+ if (!instance->context)
219
+ return;
220
+
221
+ context = (tfContext*)instance->context;
222
+ PubSub_UnsubscribeChannelConnected(instance->context->pubSub,
223
+ tf_OnChannelConnectedEventHandler);
224
+ PubSub_UnsubscribeChannelDisconnected(instance->context->pubSub,
225
+ tf_OnChannelDisconnectedEventHandler);
226
+ gdi_free(instance);
227
+ /* TODO : Clean up custom stuff */
228
+ WINPR_UNUSED(context);
229
+ }
230
+
231
+ /* RDP main loop.
232
+ * Connects RDP, loops while running and handles event and dispatch, cleans up
233
+ * after the connection ends. */
234
+ static DWORD WINAPI tf_client_thread_proc(LPVOID arg)
235
+ {
236
+ freerdp* instance = (freerdp*)arg;
237
+ DWORD nCount = 0;
238
+ DWORD status = 0;
239
+ DWORD result = 0;
240
+ HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
241
+ BOOL rc = freerdp_connect(instance);
242
+
243
+ WINPR_ASSERT(instance->context);
244
+ WINPR_ASSERT(instance->context->settings);
245
+ if (freerdp_settings_get_bool(instance->context->settings, FreeRDP_AuthenticationOnly))
246
+ {
247
+ result = freerdp_get_last_error(instance->context);
248
+ freerdp_abort_connect_context(instance->context);
249
+ WLog_ERR(TAG, "Authentication only, exit status 0x%08" PRIx32 "", result);
250
+ goto disconnect;
251
+ }
252
+
253
+ if (!rc)
254
+ {
255
+ result = freerdp_get_last_error(instance->context);
256
+ WLog_ERR(TAG, "connection failure 0x%08" PRIx32, result);
257
+ return result;
258
+ }
259
+
260
+ while (!freerdp_shall_disconnect_context(instance->context))
261
+ {
262
+ nCount = freerdp_get_event_handles(instance->context, handles, ARRAYSIZE(handles));
263
+
264
+ if (nCount == 0)
265
+ {
266
+ WLog_ERR(TAG, "freerdp_get_event_handles failed");
267
+ break;
268
+ }
269
+
270
+ status = WaitForMultipleObjects(nCount, handles, FALSE, 100);
271
+
272
+ if (status == WAIT_FAILED)
273
+ {
274
+ WLog_ERR(TAG, "WaitForMultipleObjects failed with %" PRIu32 "", status);
275
+ break;
276
+ }
277
+
278
+ if (!freerdp_check_event_handles(instance->context))
279
+ {
280
+ if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_SUCCESS)
281
+ WLog_ERR(TAG, "Failed to check FreeRDP event handles");
282
+
283
+ break;
284
+ }
285
+ }
286
+
287
+ disconnect:
288
+ freerdp_disconnect(instance);
289
+ return result;
290
+ }
291
+
292
+ /* Optional global initializer.
293
+ * Here we just register a signal handler to print out stack traces
294
+ * if available. */
295
+ static BOOL tf_client_global_init(void)
296
+ {
297
+ if (freerdp_handle_signals() != 0)
298
+ return FALSE;
299
+
300
+ return TRUE;
301
+ }
302
+
303
+ /* Optional global tear down */
304
+ static void tf_client_global_uninit(void)
305
+ {
306
+ }
307
+
308
+ static int tf_logon_error_info(freerdp* instance, UINT32 data, UINT32 type)
309
+ {
310
+ tfContext* tf = NULL;
311
+ const char* str_data = freerdp_get_logon_error_info_data(data);
312
+ const char* str_type = freerdp_get_logon_error_info_type(type);
313
+
314
+ if (!instance || !instance->context)
315
+ return -1;
316
+
317
+ tf = (tfContext*)instance->context;
318
+ WLog_INFO(TAG, "Logon Error Info %s [%s]", str_data, str_type);
319
+ WINPR_UNUSED(tf);
320
+
321
+ return 1;
322
+ }
323
+
324
+ static BOOL tf_client_new(freerdp* instance, rdpContext* context)
325
+ {
326
+ tfContext* tf = (tfContext*)context;
327
+
328
+ if (!instance || !context)
329
+ return FALSE;
330
+
331
+ instance->PreConnect = tf_pre_connect;
332
+ instance->PostConnect = tf_post_connect;
333
+ instance->PostDisconnect = tf_post_disconnect;
334
+ instance->LogonErrorInfo = tf_logon_error_info;
335
+ /* TODO: Client display set up */
336
+ WINPR_UNUSED(tf);
337
+ return TRUE;
338
+ }
339
+
340
+ static void tf_client_free(freerdp* instance, rdpContext* context)
341
+ {
342
+ tfContext* tf = (tfContext*)instance->context;
343
+
344
+ if (!context)
345
+ return;
346
+
347
+ /* TODO: Client display tear down */
348
+ WINPR_UNUSED(tf);
349
+ }
350
+
351
+ static int tf_client_start(rdpContext* context)
352
+ {
353
+ /* TODO: Start client related stuff */
354
+ WINPR_UNUSED(context);
355
+ return 0;
356
+ }
357
+
358
+ static int tf_client_stop(rdpContext* context)
359
+ {
360
+ /* TODO: Stop client related stuff */
361
+ WINPR_UNUSED(context);
362
+ return 0;
363
+ }
364
+
365
+ static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
366
+ {
367
+ WINPR_ASSERT(pEntryPoints);
368
+
369
+ ZeroMemory(pEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS));
370
+ pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION;
371
+ pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
372
+ pEntryPoints->GlobalInit = tf_client_global_init;
373
+ pEntryPoints->GlobalUninit = tf_client_global_uninit;
374
+ pEntryPoints->ContextSize = sizeof(tfContext);
375
+ pEntryPoints->ClientNew = tf_client_new;
376
+ pEntryPoints->ClientFree = tf_client_free;
377
+ pEntryPoints->ClientStart = tf_client_start;
378
+ pEntryPoints->ClientStop = tf_client_stop;
379
+ return 0;
380
+ }
381
+
382
+ int main(int argc, char* argv[])
383
+ {
384
+ int rc = -1;
385
+ RDP_CLIENT_ENTRY_POINTS clientEntryPoints = { 0 };
386
+
387
+ RdpClientEntry(&clientEntryPoints);
388
+ rdpContext* context = freerdp_client_context_new(&clientEntryPoints);
389
+
390
+ if (!context)
391
+ goto fail;
392
+
393
+ const int status =
394
+ freerdp_client_settings_parse_command_line(context->settings, argc, argv, FALSE);
395
+ if (status)
396
+ {
397
+ rc = freerdp_client_settings_command_line_status_print(context->settings, status, argc,
398
+ argv);
399
+ goto fail;
400
+ }
401
+
402
+ if (!stream_dump_register_handlers(context, CONNECTION_STATE_MCS_CREATE_REQUEST, FALSE))
403
+ goto fail;
404
+
405
+ if (freerdp_client_start(context) != 0)
406
+ goto fail;
407
+
408
+ const DWORD res = tf_client_thread_proc(context->instance);
409
+ rc = (int)res;
410
+
411
+ if (freerdp_client_stop(context) != 0)
412
+ rc = -1;
413
+
414
+ fail:
415
+ freerdp_client_context_free(context);
416
+ return rc;
417
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Sample/tf_freerdp.h ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Sample Client
4
+ *
5
+ * Copyright 2018 Armin Novak <[email protected]>
6
+ * Copyright 2018 Thincast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #ifndef FREERDP_CLIENT_SAMPLE_H
22
+ #define FREERDP_CLIENT_SAMPLE_H
23
+
24
+ #include <freerdp/freerdp.h>
25
+ #include <freerdp/client/rdpei.h>
26
+ #include <freerdp/client/rail.h>
27
+ #include <freerdp/client/cliprdr.h>
28
+ #include <freerdp/client/rdpgfx.h>
29
+
30
+ typedef struct
31
+ {
32
+ rdpClientContext common;
33
+
34
+ /* Channels */
35
+ } tfContext;
36
+
37
+ #endif /* FREERDP_CLIENT_SAMPLE_H */
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/CMakeLists.txt ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FreeRDP: A Remote Desktop Protocol Implementation
2
+ # FreeRDP Wayland Client cmake build script
3
+ #
4
+ # Copyright 2014 Manuel Bachmann <[email protected]>
5
+ # Copyright 2015 David Fort <[email protected]>
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ set(MODULE_NAME "wlfreerdp")
20
+ set(MODULE_PREFIX "FREERDP_CLIENT_WAYLAND")
21
+
22
+ include_directories(SYSTEM ${WAYLAND_INCLUDE_DIR})
23
+
24
+ set(${MODULE_PREFIX}_SRCS
25
+ wlfreerdp.c
26
+ wlfreerdp.h
27
+ wlf_disp.c
28
+ wlf_disp.h
29
+ wlf_pointer.c
30
+ wlf_pointer.h
31
+ wlf_input.c
32
+ wlf_input.h
33
+ wlf_cliprdr.c
34
+ wlf_cliprdr.h
35
+ wlf_channels.c
36
+ wlf_channels.h
37
+ )
38
+
39
+ if(FREERDP_UNIFIED_BUILD)
40
+ include_directories(${PROJECT_SOURCE_DIR}/uwac/include)
41
+ include_directories(${PROJECT_BINARY_DIR}/uwac/include)
42
+ else()
43
+ find_package(uwac 0 REQUIRED)
44
+ include_directories(SYSTEM ${UWAC_INCLUDE_DIR})
45
+ endif()
46
+
47
+ list(APPEND ${MODULE_PREFIX}_LIBS freerdp-client freerdp uwac)
48
+
49
+ addtargetwithresourcefile(${MODULE_NAME} TRUE ${FREERDP_VERSION} ${MODULE_PREFIX}_SRCS)
50
+
51
+ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
52
+
53
+ install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT client)
54
+
55
+ set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Client/Wayland")
56
+ generate_and_install_freerdp_man_from_template(${MODULE_NAME} "1" "${FREERDP_API_VERSION}")
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_channels.c ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * X11 Client Channels
4
+ *
5
+ * Copyright 2013 Marc-Andre Moreau <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #include <freerdp/config.h>
21
+
22
+ #include <freerdp/gdi/gfx.h>
23
+
24
+ #include <freerdp/gdi/video.h>
25
+
26
+ #include "wlf_channels.h"
27
+ #include "wlf_cliprdr.h"
28
+ #include "wlf_disp.h"
29
+ #include "wlfreerdp.h"
30
+
31
+ void wlf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e)
32
+ {
33
+ wlfContext* wlf = (wlfContext*)context;
34
+
35
+ WINPR_ASSERT(wlf);
36
+ WINPR_ASSERT(e);
37
+
38
+ if (FALSE)
39
+ {
40
+ }
41
+ else if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0)
42
+ {
43
+ }
44
+ else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
45
+ {
46
+ wlf_cliprdr_init(wlf->clipboard, (CliprdrClientContext*)e->pInterface);
47
+ }
48
+ else if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0)
49
+ {
50
+ wlf_disp_init(wlf->disp, (DispClientContext*)e->pInterface);
51
+ }
52
+ else
53
+ freerdp_client_OnChannelConnectedEventHandler(context, e);
54
+ }
55
+
56
+ void wlf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e)
57
+ {
58
+ wlfContext* wlf = (wlfContext*)context;
59
+
60
+ WINPR_ASSERT(wlf);
61
+ WINPR_ASSERT(e);
62
+
63
+ if (FALSE)
64
+ {
65
+ }
66
+ else if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0)
67
+ {
68
+ }
69
+ else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
70
+ {
71
+ wlf_cliprdr_uninit(wlf->clipboard, (CliprdrClientContext*)e->pInterface);
72
+ }
73
+ else if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0)
74
+ {
75
+ wlf_disp_uninit(wlf->disp, (DispClientContext*)e->pInterface);
76
+ }
77
+ else
78
+ freerdp_client_OnChannelDisconnectedEventHandler(context, e);
79
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_channels.h ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * X11 Client Channels
4
+ *
5
+ * Copyright 2013 Marc-Andre Moreau <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_CLIENT_WAYLAND_CHANNELS_H
21
+ #define FREERDP_CLIENT_WAYLAND_CHANNELS_H
22
+
23
+ #include <freerdp/freerdp.h>
24
+ #include <freerdp/client/channels.h>
25
+ #include <freerdp/client/rdpei.h>
26
+ #include <freerdp/client/rail.h>
27
+ #include <freerdp/client/cliprdr.h>
28
+ #include <freerdp/client/rdpgfx.h>
29
+ #include <freerdp/client/encomsp.h>
30
+
31
+ int wlf_on_channel_connected(freerdp* instance, const char* name, void* pInterface);
32
+ int wlf_on_channel_disconnected(freerdp* instance, const char* name, void* pInterface);
33
+
34
+ void wlf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e);
35
+ void wlf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e);
36
+
37
+ #endif /* FREERDP_CLIENT_WAYLAND_CHANNELS_H */
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_cliprdr.c ADDED
@@ -0,0 +1,1018 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Wayland Clipboard Redirection
4
+ *
5
+ * Copyright 2018 Armin Novak <[email protected]>
6
+ * Copyright 2018 Thincast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #include <freerdp/config.h>
22
+
23
+ #include <stdlib.h>
24
+
25
+ #include <winpr/crt.h>
26
+ #include <winpr/image.h>
27
+ #include <winpr/stream.h>
28
+ #include <winpr/clipboard.h>
29
+
30
+ #include <freerdp/log.h>
31
+ #include <freerdp/client/cliprdr.h>
32
+ #include <freerdp/channels/channels.h>
33
+ #include <freerdp/channels/cliprdr.h>
34
+
35
+ #include <freerdp/client/client_cliprdr_file.h>
36
+
37
+ #include "wlf_cliprdr.h"
38
+
39
+ #define TAG CLIENT_TAG("wayland.cliprdr")
40
+
41
+ #define mime_text_plain "text/plain"
42
+ // NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
43
+ static const char mime_text_utf8[] = mime_text_plain ";charset=utf-8";
44
+
45
+ // NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
46
+ static const char* mime_text[] = { mime_text_plain, mime_text_utf8, "UTF8_STRING",
47
+ "COMPOUND_TEXT", "TEXT", "STRING" };
48
+
49
+ static const char mime_png[] = "image/png";
50
+ static const char mime_webp[] = "image/webp";
51
+ static const char mime_jpg[] = "image/jpeg";
52
+ static const char mime_tiff[] = "image/tiff";
53
+ static const char mime_uri_list[] = "text/uri-list";
54
+ static const char mime_html[] = "text/html";
55
+
56
+ #define BMP_MIME_LIST "image/bmp", "image/x-bmp", "image/x-MS-bmp", "image/x-win-bitmap"
57
+ static const char* mime_bitmap[] = { BMP_MIME_LIST };
58
+ static const char* mime_image[] = { mime_png, mime_webp, mime_jpg, mime_tiff, BMP_MIME_LIST };
59
+
60
+ static const char mime_gnome_copied_files[] = "x-special/gnome-copied-files";
61
+ static const char mime_mate_copied_files[] = "x-special/mate-copied-files";
62
+
63
+ static const char type_FileGroupDescriptorW[] = "FileGroupDescriptorW";
64
+ static const char type_HtmlFormat[] = "HTML Format";
65
+
66
+ typedef struct
67
+ {
68
+ FILE* responseFile;
69
+ UINT32 responseFormat;
70
+ char* responseMime;
71
+ } wlf_request;
72
+
73
+ typedef struct
74
+ {
75
+ const FILE* responseFile;
76
+ UINT32 responseFormat;
77
+ const char* responseMime;
78
+ } wlf_const_request;
79
+
80
+ struct wlf_clipboard
81
+ {
82
+ wlfContext* wfc;
83
+ rdpChannels* channels;
84
+ CliprdrClientContext* context;
85
+ wLog* log;
86
+
87
+ UwacSeat* seat;
88
+ wClipboard* system;
89
+
90
+ size_t numClientFormats;
91
+ CLIPRDR_FORMAT* clientFormats;
92
+
93
+ size_t numServerFormats;
94
+ CLIPRDR_FORMAT* serverFormats;
95
+
96
+ BOOL sync;
97
+
98
+ CRITICAL_SECTION lock;
99
+ CliprdrFileContext* file;
100
+
101
+ wQueue* request_queue;
102
+ };
103
+
104
+ static void wlf_request_free(void* rq)
105
+ {
106
+ wlf_request* request = rq;
107
+ if (request)
108
+ {
109
+ free(request->responseMime);
110
+ if (request->responseFile)
111
+ (void)fclose(request->responseFile);
112
+ }
113
+ free(request);
114
+ }
115
+
116
+ static wlf_request* wlf_request_new(void)
117
+ {
118
+ return calloc(1, sizeof(wlf_request));
119
+ }
120
+
121
+ static void* wlf_request_clone(const void* oth)
122
+ {
123
+ const wlf_request* other = (const wlf_request*)oth;
124
+ wlf_request* copy = wlf_request_new();
125
+ if (!copy)
126
+ return NULL;
127
+ *copy = *other;
128
+ if (other->responseMime)
129
+ {
130
+ copy->responseMime = _strdup(other->responseMime);
131
+ if (!copy->responseMime)
132
+ goto fail;
133
+ }
134
+ return copy;
135
+ fail:
136
+ wlf_request_free(copy);
137
+ return NULL;
138
+ }
139
+
140
+ static BOOL wlf_mime_is_file(const char* mime)
141
+ {
142
+ if (strncmp(mime_uri_list, mime, sizeof(mime_uri_list)) == 0)
143
+ return TRUE;
144
+ if (strncmp(mime_gnome_copied_files, mime, sizeof(mime_gnome_copied_files)) == 0)
145
+ return TRUE;
146
+ if (strncmp(mime_mate_copied_files, mime, sizeof(mime_mate_copied_files)) == 0)
147
+ return TRUE;
148
+ return FALSE;
149
+ }
150
+
151
+ static BOOL wlf_mime_is_text(const char* mime)
152
+ {
153
+ for (size_t x = 0; x < ARRAYSIZE(mime_text); x++)
154
+ {
155
+ if (strcmp(mime, mime_text[x]) == 0)
156
+ return TRUE;
157
+ }
158
+
159
+ return FALSE;
160
+ }
161
+
162
+ static BOOL wlf_mime_is_image(const char* mime)
163
+ {
164
+ for (size_t x = 0; x < ARRAYSIZE(mime_image); x++)
165
+ {
166
+ if (strcmp(mime, mime_image[x]) == 0)
167
+ return TRUE;
168
+ }
169
+
170
+ return FALSE;
171
+ }
172
+
173
+ static BOOL wlf_mime_is_html(const char* mime)
174
+ {
175
+ if (strcmp(mime, mime_html) == 0)
176
+ return TRUE;
177
+
178
+ return FALSE;
179
+ }
180
+
181
+ static void wlf_cliprdr_free_server_formats(wfClipboard* clipboard)
182
+ {
183
+ if (clipboard && clipboard->serverFormats)
184
+ {
185
+ for (size_t j = 0; j < clipboard->numServerFormats; j++)
186
+ {
187
+ CLIPRDR_FORMAT* format = &clipboard->serverFormats[j];
188
+ free(format->formatName);
189
+ }
190
+
191
+ free(clipboard->serverFormats);
192
+ clipboard->serverFormats = NULL;
193
+ clipboard->numServerFormats = 0;
194
+ }
195
+
196
+ if (clipboard)
197
+ UwacClipboardOfferDestroy(clipboard->seat);
198
+ }
199
+
200
+ static void wlf_cliprdr_free_client_formats(wfClipboard* clipboard)
201
+ {
202
+ if (clipboard && clipboard->numClientFormats)
203
+ {
204
+ for (size_t j = 0; j < clipboard->numClientFormats; j++)
205
+ {
206
+ CLIPRDR_FORMAT* format = &clipboard->clientFormats[j];
207
+ free(format->formatName);
208
+ }
209
+
210
+ free(clipboard->clientFormats);
211
+ clipboard->clientFormats = NULL;
212
+ clipboard->numClientFormats = 0;
213
+ }
214
+
215
+ if (clipboard)
216
+ UwacClipboardOfferDestroy(clipboard->seat);
217
+ }
218
+
219
+ /**
220
+ * Function description
221
+ *
222
+ * @return 0 on success, otherwise a Win32 error code
223
+ */
224
+ static UINT wlf_cliprdr_send_client_format_list(wfClipboard* clipboard)
225
+ {
226
+ WINPR_ASSERT(clipboard);
227
+
228
+ const CLIPRDR_FORMAT_LIST formatList = { .common.msgFlags = 0,
229
+ .numFormats = (UINT32)clipboard->numClientFormats,
230
+ .formats = clipboard->clientFormats,
231
+ .common.msgType = CB_FORMAT_LIST };
232
+
233
+ cliprdr_file_context_clear(clipboard->file);
234
+
235
+ WLog_VRB(TAG, "-------------- client format list [%" PRIu32 "] ------------------",
236
+ formatList.numFormats);
237
+ for (UINT32 x = 0; x < formatList.numFormats; x++)
238
+ {
239
+ const CLIPRDR_FORMAT* format = &formatList.formats[x];
240
+ WLog_VRB(TAG, "client announces %" PRIu32 " [%s][%s]", format->formatId,
241
+ ClipboardGetFormatIdString(format->formatId), format->formatName);
242
+ }
243
+ WINPR_ASSERT(clipboard->context);
244
+ WINPR_ASSERT(clipboard->context->ClientFormatList);
245
+ return clipboard->context->ClientFormatList(clipboard->context, &formatList);
246
+ }
247
+
248
+ static void wfl_cliprdr_add_client_format_id(wfClipboard* clipboard, UINT32 formatId)
249
+ {
250
+ CLIPRDR_FORMAT* format = NULL;
251
+ const char* name = ClipboardGetFormatName(clipboard->system, formatId);
252
+
253
+ for (size_t x = 0; x < clipboard->numClientFormats; x++)
254
+ {
255
+ format = &clipboard->clientFormats[x];
256
+
257
+ if (format->formatId == formatId)
258
+ return;
259
+ }
260
+
261
+ format = realloc(clipboard->clientFormats,
262
+ (clipboard->numClientFormats + 1) * sizeof(CLIPRDR_FORMAT));
263
+
264
+ if (!format)
265
+ return;
266
+
267
+ clipboard->clientFormats = format;
268
+ format = &clipboard->clientFormats[clipboard->numClientFormats++];
269
+ format->formatId = formatId;
270
+ format->formatName = NULL;
271
+
272
+ if (name && (formatId >= CF_MAX))
273
+ format->formatName = _strdup(name);
274
+ }
275
+
276
+ static BOOL wlf_cliprdr_add_client_format(wfClipboard* clipboard, const char* mime)
277
+ {
278
+ WINPR_ASSERT(mime);
279
+ ClipboardLock(clipboard->system);
280
+ if (wlf_mime_is_html(mime))
281
+ {
282
+ UINT32 formatId = ClipboardGetFormatId(clipboard->system, type_HtmlFormat);
283
+ wfl_cliprdr_add_client_format_id(clipboard, formatId);
284
+ }
285
+ else if (wlf_mime_is_text(mime))
286
+ {
287
+ wfl_cliprdr_add_client_format_id(clipboard, CF_TEXT);
288
+ wfl_cliprdr_add_client_format_id(clipboard, CF_OEMTEXT);
289
+ wfl_cliprdr_add_client_format_id(clipboard, CF_UNICODETEXT);
290
+ }
291
+ else if (wlf_mime_is_image(mime))
292
+ {
293
+ for (size_t x = 0; x < ARRAYSIZE(mime_image); x++)
294
+ {
295
+ const char* mime_bmp = mime_image[x];
296
+ UINT32 formatId = ClipboardGetFormatId(clipboard->system, mime_bmp);
297
+ if (formatId != 0)
298
+ wfl_cliprdr_add_client_format_id(clipboard, formatId);
299
+ }
300
+ wfl_cliprdr_add_client_format_id(clipboard, CF_DIB);
301
+ wfl_cliprdr_add_client_format_id(clipboard, CF_TIFF);
302
+ }
303
+ else if (wlf_mime_is_file(mime))
304
+ {
305
+ const UINT32 fileFormatId =
306
+ ClipboardGetFormatId(clipboard->system, type_FileGroupDescriptorW);
307
+ wfl_cliprdr_add_client_format_id(clipboard, fileFormatId);
308
+ }
309
+
310
+ ClipboardUnlock(clipboard->system);
311
+ if (wlf_cliprdr_send_client_format_list(clipboard) != CHANNEL_RC_OK)
312
+ return FALSE;
313
+ return TRUE;
314
+ }
315
+
316
+ /**
317
+ * Function description
318
+ *
319
+ * @return 0 on success, otherwise a Win32 error code
320
+ */
321
+ static UINT wlf_cliprdr_send_data_request(wfClipboard* clipboard, const wlf_const_request* rq)
322
+ {
323
+ WINPR_ASSERT(rq);
324
+
325
+ CLIPRDR_FORMAT_DATA_REQUEST request = { .requestedFormatId = rq->responseFormat };
326
+
327
+ if (!Queue_Enqueue(clipboard->request_queue, rq))
328
+ return ERROR_INTERNAL_ERROR;
329
+
330
+ WINPR_ASSERT(clipboard);
331
+ WINPR_ASSERT(clipboard->context);
332
+ WINPR_ASSERT(clipboard->context->ClientFormatDataRequest);
333
+ return clipboard->context->ClientFormatDataRequest(clipboard->context, &request);
334
+ }
335
+
336
+ /**
337
+ * Function description
338
+ *
339
+ * @return 0 on success, otherwise a Win32 error code
340
+ */
341
+ static UINT wlf_cliprdr_send_data_response(wfClipboard* clipboard, const BYTE* data, size_t size)
342
+ {
343
+ CLIPRDR_FORMAT_DATA_RESPONSE response = { 0 };
344
+
345
+ if (size > UINT32_MAX)
346
+ return ERROR_INVALID_PARAMETER;
347
+
348
+ response.common.msgFlags = (data) ? CB_RESPONSE_OK : CB_RESPONSE_FAIL;
349
+ response.common.dataLen = (UINT32)size;
350
+ response.requestedFormatData = data;
351
+
352
+ WINPR_ASSERT(clipboard);
353
+ WINPR_ASSERT(clipboard->context);
354
+ WINPR_ASSERT(clipboard->context->ClientFormatDataResponse);
355
+ return clipboard->context->ClientFormatDataResponse(clipboard->context, &response);
356
+ }
357
+
358
+ BOOL wlf_cliprdr_handle_event(wfClipboard* clipboard, const UwacClipboardEvent* event)
359
+ {
360
+ if (!clipboard || !event)
361
+ return FALSE;
362
+
363
+ if (!clipboard->context)
364
+ return TRUE;
365
+
366
+ switch (event->type)
367
+ {
368
+ case UWAC_EVENT_CLIPBOARD_AVAILABLE:
369
+ clipboard->seat = event->seat;
370
+ return TRUE;
371
+
372
+ case UWAC_EVENT_CLIPBOARD_OFFER:
373
+ WLog_Print(clipboard->log, WLOG_DEBUG, "client announces mime %s", event->mime);
374
+ return wlf_cliprdr_add_client_format(clipboard, event->mime);
375
+
376
+ case UWAC_EVENT_CLIPBOARD_SELECT:
377
+ WLog_Print(clipboard->log, WLOG_DEBUG, "client announces new data");
378
+ wlf_cliprdr_free_client_formats(clipboard);
379
+ return TRUE;
380
+
381
+ default:
382
+ return FALSE;
383
+ }
384
+ }
385
+
386
+ /**
387
+ * Function description
388
+ *
389
+ * @return 0 on success, otherwise a Win32 error code
390
+ */
391
+ static UINT wlf_cliprdr_send_client_capabilities(wfClipboard* clipboard)
392
+ {
393
+ WINPR_ASSERT(clipboard);
394
+
395
+ CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet = {
396
+ .capabilitySetType = CB_CAPSTYPE_GENERAL,
397
+ .capabilitySetLength = 12,
398
+ .version = CB_CAPS_VERSION_2,
399
+ .generalFlags =
400
+ CB_USE_LONG_FORMAT_NAMES | cliprdr_file_context_current_flags(clipboard->file)
401
+ };
402
+ CLIPRDR_CAPABILITIES capabilities = { .cCapabilitiesSets = 1,
403
+ .capabilitySets =
404
+ (CLIPRDR_CAPABILITY_SET*)&(generalCapabilitySet) };
405
+
406
+ WINPR_ASSERT(clipboard);
407
+ WINPR_ASSERT(clipboard->context);
408
+ WINPR_ASSERT(clipboard->context->ClientCapabilities);
409
+ return clipboard->context->ClientCapabilities(clipboard->context, &capabilities);
410
+ }
411
+
412
+ /**
413
+ * Function description
414
+ *
415
+ * @return 0 on success, otherwise a Win32 error code
416
+ */
417
+ static UINT wlf_cliprdr_send_client_format_list_response(wfClipboard* clipboard, BOOL status)
418
+ {
419
+ const CLIPRDR_FORMAT_LIST_RESPONSE formatListResponse = {
420
+ .common.msgType = CB_FORMAT_LIST_RESPONSE,
421
+ .common.msgFlags = status ? CB_RESPONSE_OK : CB_RESPONSE_FAIL,
422
+ .common.dataLen = 0
423
+ };
424
+ WINPR_ASSERT(clipboard);
425
+ WINPR_ASSERT(clipboard->context);
426
+ WINPR_ASSERT(clipboard->context->ClientFormatListResponse);
427
+ return clipboard->context->ClientFormatListResponse(clipboard->context, &formatListResponse);
428
+ }
429
+
430
+ /**
431
+ * Function description
432
+ *
433
+ * @return 0 on success, otherwise a Win32 error code
434
+ */
435
+ static UINT wlf_cliprdr_monitor_ready(CliprdrClientContext* context,
436
+ const CLIPRDR_MONITOR_READY* monitorReady)
437
+ {
438
+ UINT ret = 0;
439
+
440
+ WINPR_UNUSED(monitorReady);
441
+ WINPR_ASSERT(context);
442
+ WINPR_ASSERT(monitorReady);
443
+
444
+ wfClipboard* clipboard = cliprdr_file_context_get_context(context->custom);
445
+ WINPR_ASSERT(clipboard);
446
+
447
+ if ((ret = wlf_cliprdr_send_client_capabilities(clipboard)) != CHANNEL_RC_OK)
448
+ return ret;
449
+
450
+ if ((ret = wlf_cliprdr_send_client_format_list(clipboard)) != CHANNEL_RC_OK)
451
+ return ret;
452
+
453
+ clipboard->sync = TRUE;
454
+ return CHANNEL_RC_OK;
455
+ }
456
+
457
+ /**
458
+ * Function description
459
+ *
460
+ * @return 0 on success, otherwise a Win32 error code
461
+ */
462
+ static UINT wlf_cliprdr_server_capabilities(CliprdrClientContext* context,
463
+ const CLIPRDR_CAPABILITIES* capabilities)
464
+ {
465
+ WINPR_ASSERT(context);
466
+ WINPR_ASSERT(capabilities);
467
+
468
+ const BYTE* capsPtr = (const BYTE*)capabilities->capabilitySets;
469
+ WINPR_ASSERT(capsPtr);
470
+
471
+ wfClipboard* clipboard = cliprdr_file_context_get_context(context->custom);
472
+ WINPR_ASSERT(clipboard);
473
+
474
+ if (!cliprdr_file_context_remote_set_flags(clipboard->file, 0))
475
+ return ERROR_INTERNAL_ERROR;
476
+
477
+ for (UINT32 i = 0; i < capabilities->cCapabilitiesSets; i++)
478
+ {
479
+ const CLIPRDR_CAPABILITY_SET* caps = (const CLIPRDR_CAPABILITY_SET*)capsPtr;
480
+
481
+ if (caps->capabilitySetType == CB_CAPSTYPE_GENERAL)
482
+ {
483
+ const CLIPRDR_GENERAL_CAPABILITY_SET* generalCaps =
484
+ (const CLIPRDR_GENERAL_CAPABILITY_SET*)caps;
485
+
486
+ if (!cliprdr_file_context_remote_set_flags(clipboard->file, generalCaps->generalFlags))
487
+ return ERROR_INTERNAL_ERROR;
488
+ }
489
+
490
+ capsPtr += caps->capabilitySetLength;
491
+ }
492
+
493
+ return CHANNEL_RC_OK;
494
+ }
495
+
496
+ static UINT32 wlf_get_server_format_id(const wfClipboard* clipboard, const char* name)
497
+ {
498
+ WINPR_ASSERT(clipboard);
499
+ WINPR_ASSERT(name);
500
+
501
+ for (UINT32 x = 0; x < clipboard->numServerFormats; x++)
502
+ {
503
+ const CLIPRDR_FORMAT* format = &clipboard->serverFormats[x];
504
+ if (!format->formatName)
505
+ continue;
506
+ if (strcmp(name, format->formatName) == 0)
507
+ return format->formatId;
508
+ }
509
+ return 0;
510
+ }
511
+
512
+ static const char* wlf_get_server_format_name(const wfClipboard* clipboard, UINT32 formatId)
513
+ {
514
+ WINPR_ASSERT(clipboard);
515
+
516
+ for (UINT32 x = 0; x < clipboard->numServerFormats; x++)
517
+ {
518
+ const CLIPRDR_FORMAT* format = &clipboard->serverFormats[x];
519
+ if (format->formatId == formatId)
520
+ return format->formatName;
521
+ }
522
+ return NULL;
523
+ }
524
+
525
+ static void wlf_cliprdr_transfer_data(UwacSeat* seat, void* context, const char* mime, int fd)
526
+ {
527
+ wfClipboard* clipboard = (wfClipboard*)context;
528
+ WINPR_UNUSED(seat);
529
+
530
+ EnterCriticalSection(&clipboard->lock);
531
+
532
+ wlf_const_request request = { 0 };
533
+ if (wlf_mime_is_html(mime))
534
+ {
535
+ request.responseMime = mime_html;
536
+ request.responseFormat = wlf_get_server_format_id(clipboard, type_HtmlFormat);
537
+ }
538
+ else if (wlf_mime_is_file(mime))
539
+ {
540
+ request.responseMime = mime;
541
+ request.responseFormat = wlf_get_server_format_id(clipboard, type_FileGroupDescriptorW);
542
+ }
543
+ else if (wlf_mime_is_text(mime))
544
+ {
545
+ request.responseMime = mime_text_plain;
546
+ request.responseFormat = CF_UNICODETEXT;
547
+ }
548
+ else if (wlf_mime_is_image(mime))
549
+ {
550
+ request.responseMime = mime;
551
+ if (strcmp(mime, mime_tiff) == 0)
552
+ request.responseFormat = CF_TIFF;
553
+ else
554
+ request.responseFormat = CF_DIB;
555
+ }
556
+
557
+ if (request.responseMime != NULL)
558
+ {
559
+ request.responseFile = fdopen(fd, "w");
560
+
561
+ if (request.responseFile)
562
+ wlf_cliprdr_send_data_request(clipboard, &request);
563
+ else
564
+ WLog_Print(clipboard->log, WLOG_ERROR,
565
+ "failed to open clipboard file descriptor for MIME %s",
566
+ request.responseMime);
567
+ }
568
+
569
+ LeaveCriticalSection(&clipboard->lock);
570
+ }
571
+
572
+ static void wlf_cliprdr_cancel_data(UwacSeat* seat, void* context)
573
+ {
574
+ wfClipboard* clipboard = (wfClipboard*)context;
575
+
576
+ WINPR_UNUSED(seat);
577
+ WINPR_ASSERT(clipboard);
578
+ cliprdr_file_context_clear(clipboard->file);
579
+ }
580
+
581
+ /**
582
+ * Called when the clipboard changes server side.
583
+ *
584
+ * Clear the local clipboard offer and replace it with a new one
585
+ * that announces the formats we get listed here.
586
+ *
587
+ * @return 0 on success, otherwise a Win32 error code
588
+ */
589
+ static UINT wlf_cliprdr_server_format_list(CliprdrClientContext* context,
590
+ const CLIPRDR_FORMAT_LIST* formatList)
591
+ {
592
+ BOOL html = FALSE;
593
+ BOOL text = FALSE;
594
+ BOOL image = FALSE;
595
+ BOOL file = FALSE;
596
+
597
+ if (!context || !context->custom)
598
+ return ERROR_INVALID_PARAMETER;
599
+
600
+ wfClipboard* clipboard = cliprdr_file_context_get_context(context->custom);
601
+ WINPR_ASSERT(clipboard);
602
+
603
+ wlf_cliprdr_free_server_formats(clipboard);
604
+ cliprdr_file_context_clear(clipboard->file);
605
+
606
+ if (!(clipboard->serverFormats =
607
+ (CLIPRDR_FORMAT*)calloc(formatList->numFormats, sizeof(CLIPRDR_FORMAT))))
608
+ {
609
+ WLog_Print(clipboard->log, WLOG_ERROR,
610
+ "failed to allocate %" PRIuz " CLIPRDR_FORMAT structs",
611
+ clipboard->numServerFormats);
612
+ return CHANNEL_RC_NO_MEMORY;
613
+ }
614
+
615
+ clipboard->numServerFormats = formatList->numFormats;
616
+
617
+ if (!clipboard->seat)
618
+ {
619
+ WLog_Print(clipboard->log, WLOG_ERROR,
620
+ "clipboard->seat=NULL, check your client implementation");
621
+ return ERROR_INTERNAL_ERROR;
622
+ }
623
+
624
+ for (UINT32 i = 0; i < formatList->numFormats; i++)
625
+ {
626
+ const CLIPRDR_FORMAT* format = &formatList->formats[i];
627
+ CLIPRDR_FORMAT* srvFormat = &clipboard->serverFormats[i];
628
+ srvFormat->formatId = format->formatId;
629
+
630
+ if (format->formatName)
631
+ {
632
+ srvFormat->formatName = _strdup(format->formatName);
633
+
634
+ if (!srvFormat->formatName)
635
+ {
636
+ wlf_cliprdr_free_server_formats(clipboard);
637
+ return CHANNEL_RC_NO_MEMORY;
638
+ }
639
+ }
640
+
641
+ if (format->formatName)
642
+ {
643
+ if (strcmp(format->formatName, type_HtmlFormat) == 0)
644
+ {
645
+ text = TRUE;
646
+ html = TRUE;
647
+ }
648
+ else if (strcmp(format->formatName, type_FileGroupDescriptorW) == 0)
649
+ {
650
+ file = TRUE;
651
+ text = TRUE;
652
+ }
653
+ }
654
+ else
655
+ {
656
+ switch (format->formatId)
657
+ {
658
+ case CF_TEXT:
659
+ case CF_OEMTEXT:
660
+ case CF_UNICODETEXT:
661
+ text = TRUE;
662
+ break;
663
+
664
+ case CF_DIB:
665
+ image = TRUE;
666
+ break;
667
+
668
+ default:
669
+ break;
670
+ }
671
+ }
672
+ }
673
+
674
+ if (html)
675
+ {
676
+ UwacClipboardOfferCreate(clipboard->seat, mime_html);
677
+ }
678
+
679
+ if (file && cliprdr_file_context_has_local_support(clipboard->file))
680
+ {
681
+ UwacClipboardOfferCreate(clipboard->seat, mime_uri_list);
682
+ UwacClipboardOfferCreate(clipboard->seat, mime_gnome_copied_files);
683
+ UwacClipboardOfferCreate(clipboard->seat, mime_mate_copied_files);
684
+ }
685
+
686
+ if (text)
687
+ {
688
+ for (size_t x = 0; x < ARRAYSIZE(mime_text); x++)
689
+ UwacClipboardOfferCreate(clipboard->seat, mime_text[x]);
690
+ }
691
+
692
+ if (image)
693
+ {
694
+ for (size_t x = 0; x < ARRAYSIZE(mime_image); x++)
695
+ UwacClipboardOfferCreate(clipboard->seat, mime_image[x]);
696
+ }
697
+
698
+ UwacClipboardOfferAnnounce(clipboard->seat, clipboard, wlf_cliprdr_transfer_data,
699
+ wlf_cliprdr_cancel_data);
700
+ return wlf_cliprdr_send_client_format_list_response(clipboard, TRUE);
701
+ }
702
+
703
+ /**
704
+ * Function description
705
+ *
706
+ * @return 0 on success, otherwise a Win32 error code
707
+ */
708
+ static UINT
709
+ wlf_cliprdr_server_format_list_response(CliprdrClientContext* context,
710
+ const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
711
+ {
712
+ WINPR_ASSERT(context);
713
+ WINPR_ASSERT(formatListResponse);
714
+
715
+ if (formatListResponse->common.msgFlags & CB_RESPONSE_FAIL)
716
+ WLog_WARN(TAG, "format list update failed");
717
+ return CHANNEL_RC_OK;
718
+ }
719
+
720
+ /**
721
+ * Function description
722
+ *
723
+ * @return 0 on success, otherwise a Win32 error code
724
+ */
725
+ static UINT
726
+ wlf_cliprdr_server_format_data_request(CliprdrClientContext* context,
727
+ const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
728
+ {
729
+ UINT rc = CHANNEL_RC_OK;
730
+ char* data = NULL;
731
+ size_t size = 0;
732
+ const char* mime = NULL;
733
+ UINT32 formatId = 0;
734
+ UINT32 localFormatId = 0;
735
+ wfClipboard* clipboard = 0;
736
+
737
+ UINT32 dsize = 0;
738
+ BYTE* ddata = NULL;
739
+
740
+ WINPR_ASSERT(context);
741
+ WINPR_ASSERT(formatDataRequest);
742
+
743
+ localFormatId = formatId = formatDataRequest->requestedFormatId;
744
+ clipboard = cliprdr_file_context_get_context(context->custom);
745
+ WINPR_ASSERT(clipboard);
746
+
747
+ ClipboardLock(clipboard->system);
748
+ const UINT32 fileFormatId = ClipboardGetFormatId(clipboard->system, type_FileGroupDescriptorW);
749
+ const UINT32 htmlFormatId = ClipboardGetFormatId(clipboard->system, type_HtmlFormat);
750
+
751
+ switch (formatId)
752
+ {
753
+ case CF_TEXT:
754
+ case CF_OEMTEXT:
755
+ case CF_UNICODETEXT:
756
+ localFormatId = ClipboardGetFormatId(clipboard->system, mime_text_plain);
757
+ mime = mime_text_utf8;
758
+ break;
759
+
760
+ case CF_DIB:
761
+ case CF_DIBV5:
762
+ mime = mime_bitmap[0];
763
+ break;
764
+
765
+ case CF_TIFF:
766
+ mime = mime_tiff;
767
+ break;
768
+
769
+ default:
770
+ if (formatId == fileFormatId)
771
+ {
772
+ localFormatId = ClipboardGetFormatId(clipboard->system, mime_uri_list);
773
+ mime = mime_uri_list;
774
+ }
775
+ else if (formatId == htmlFormatId)
776
+ {
777
+ localFormatId = ClipboardGetFormatId(clipboard->system, mime_html);
778
+ mime = mime_html;
779
+ }
780
+ else
781
+ goto fail;
782
+ break;
783
+ }
784
+
785
+ data = UwacClipboardDataGet(clipboard->seat, mime, &size);
786
+
787
+ if (!data || (size > UINT32_MAX))
788
+ goto fail;
789
+
790
+ if (fileFormatId == formatId)
791
+ {
792
+ if (!cliprdr_file_context_update_client_data(clipboard->file, data, size))
793
+ goto fail;
794
+ }
795
+
796
+ const BOOL res = ClipboardSetData(clipboard->system, localFormatId, data, (UINT32)size);
797
+ free(data);
798
+
799
+ UINT32 len = 0;
800
+ data = NULL;
801
+ if (res)
802
+ data = ClipboardGetData(clipboard->system, formatId, &len);
803
+
804
+ if (!res || !data)
805
+ goto fail;
806
+
807
+ if (fileFormatId == formatId)
808
+ {
809
+ const UINT32 flags = cliprdr_file_context_remote_get_flags(clipboard->file);
810
+ const UINT32 error = cliprdr_serialize_file_list_ex(
811
+ flags, (const FILEDESCRIPTORW*)data, len / sizeof(FILEDESCRIPTORW), &ddata, &dsize);
812
+ if (error)
813
+ goto fail;
814
+ }
815
+ fail:
816
+ ClipboardUnlock(clipboard->system);
817
+ rc = wlf_cliprdr_send_data_response(clipboard, ddata, dsize);
818
+ free(data);
819
+ return rc;
820
+ }
821
+
822
+ /**
823
+ * Function description
824
+ *
825
+ * @return 0 on success, otherwise a Win32 error code
826
+ */
827
+ static UINT
828
+ wlf_cliprdr_server_format_data_response(CliprdrClientContext* context,
829
+ const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
830
+ {
831
+ UINT rc = ERROR_INTERNAL_ERROR;
832
+
833
+ WINPR_ASSERT(context);
834
+ WINPR_ASSERT(formatDataResponse);
835
+
836
+ const UINT32 size = formatDataResponse->common.dataLen;
837
+ const BYTE* data = formatDataResponse->requestedFormatData;
838
+
839
+ wfClipboard* clipboard = cliprdr_file_context_get_context(context->custom);
840
+ WINPR_ASSERT(clipboard);
841
+
842
+ wlf_request* request = Queue_Dequeue(clipboard->request_queue);
843
+ if (!request)
844
+ goto fail;
845
+
846
+ rc = CHANNEL_RC_OK;
847
+ if (formatDataResponse->common.msgFlags & CB_RESPONSE_FAIL)
848
+ {
849
+ WLog_WARN(TAG, "clipboard data request for format %" PRIu32 " [%s], mime %s failed",
850
+ request->responseFormat, ClipboardGetFormatIdString(request->responseFormat),
851
+ request->responseMime);
852
+ goto fail;
853
+ }
854
+ rc = ERROR_INTERNAL_ERROR;
855
+
856
+ ClipboardLock(clipboard->system);
857
+ EnterCriticalSection(&clipboard->lock);
858
+
859
+ BYTE* cdata = NULL;
860
+ UINT32 srcFormatId = 0;
861
+ UINT32 dstFormatId = 0;
862
+ switch (request->responseFormat)
863
+ {
864
+ case CF_TEXT:
865
+ case CF_OEMTEXT:
866
+ case CF_UNICODETEXT:
867
+ srcFormatId = request->responseFormat;
868
+ dstFormatId = ClipboardGetFormatId(clipboard->system, request->responseMime);
869
+ break;
870
+
871
+ case CF_DIB:
872
+ case CF_DIBV5:
873
+ srcFormatId = request->responseFormat;
874
+ dstFormatId = ClipboardGetFormatId(clipboard->system, request->responseMime);
875
+ break;
876
+
877
+ default:
878
+ {
879
+ const char* name = wlf_get_server_format_name(clipboard, request->responseFormat);
880
+ if (name)
881
+ {
882
+ if (strcmp(type_FileGroupDescriptorW, name) == 0)
883
+ {
884
+ srcFormatId =
885
+ ClipboardGetFormatId(clipboard->system, type_FileGroupDescriptorW);
886
+ dstFormatId = ClipboardGetFormatId(clipboard->system, request->responseMime);
887
+
888
+ if (!cliprdr_file_context_update_server_data(clipboard->file, clipboard->system,
889
+ data, size))
890
+ goto unlock;
891
+ }
892
+ else if (strcmp(type_HtmlFormat, name) == 0)
893
+ {
894
+ srcFormatId = ClipboardGetFormatId(clipboard->system, type_HtmlFormat);
895
+ dstFormatId = ClipboardGetFormatId(clipboard->system, request->responseMime);
896
+ }
897
+ }
898
+ }
899
+ break;
900
+ }
901
+
902
+ UINT32 len = 0;
903
+
904
+ const BOOL sres = ClipboardSetData(clipboard->system, srcFormatId, data, size);
905
+ if (sres)
906
+ cdata = ClipboardGetData(clipboard->system, dstFormatId, &len);
907
+
908
+ if (!sres || !cdata)
909
+ goto unlock;
910
+
911
+ if (request->responseFile)
912
+ {
913
+ const size_t res = fwrite(cdata, 1, len, request->responseFile);
914
+ if (res == len)
915
+ rc = CHANNEL_RC_OK;
916
+ }
917
+ else
918
+ rc = CHANNEL_RC_OK;
919
+
920
+ unlock:
921
+ free(cdata);
922
+ ClipboardUnlock(clipboard->system);
923
+ LeaveCriticalSection(&clipboard->lock);
924
+ fail:
925
+ wlf_request_free(request);
926
+ return rc;
927
+ }
928
+
929
+ wfClipboard* wlf_clipboard_new(wlfContext* wfc)
930
+ {
931
+ rdpChannels* channels = NULL;
932
+ wfClipboard* clipboard = NULL;
933
+
934
+ WINPR_ASSERT(wfc);
935
+
936
+ clipboard = (wfClipboard*)calloc(1, sizeof(wfClipboard));
937
+
938
+ if (!clipboard)
939
+ goto fail;
940
+
941
+ InitializeCriticalSection(&clipboard->lock);
942
+ clipboard->wfc = wfc;
943
+ channels = wfc->common.context.channels;
944
+ clipboard->log = WLog_Get(TAG);
945
+ clipboard->channels = channels;
946
+ clipboard->system = ClipboardCreate();
947
+ if (!clipboard->system)
948
+ goto fail;
949
+
950
+ clipboard->file = cliprdr_file_context_new(clipboard);
951
+ if (!clipboard->file)
952
+ goto fail;
953
+
954
+ if (!cliprdr_file_context_set_locally_available(clipboard->file, TRUE))
955
+ goto fail;
956
+
957
+ clipboard->request_queue = Queue_New(TRUE, -1, -1);
958
+ if (!clipboard->request_queue)
959
+ goto fail;
960
+
961
+ wObject* obj = Queue_Object(clipboard->request_queue);
962
+ WINPR_ASSERT(obj);
963
+ obj->fnObjectFree = wlf_request_free;
964
+ obj->fnObjectNew = wlf_request_clone;
965
+
966
+ return clipboard;
967
+
968
+ fail:
969
+ wlf_clipboard_free(clipboard);
970
+ return NULL;
971
+ }
972
+
973
+ void wlf_clipboard_free(wfClipboard* clipboard)
974
+ {
975
+ if (!clipboard)
976
+ return;
977
+
978
+ cliprdr_file_context_free(clipboard->file);
979
+
980
+ wlf_cliprdr_free_server_formats(clipboard);
981
+ wlf_cliprdr_free_client_formats(clipboard);
982
+ ClipboardDestroy(clipboard->system);
983
+
984
+ EnterCriticalSection(&clipboard->lock);
985
+
986
+ Queue_Free(clipboard->request_queue);
987
+ LeaveCriticalSection(&clipboard->lock);
988
+ DeleteCriticalSection(&clipboard->lock);
989
+ free(clipboard);
990
+ }
991
+
992
+ BOOL wlf_cliprdr_init(wfClipboard* clipboard, CliprdrClientContext* cliprdr)
993
+ {
994
+ WINPR_ASSERT(clipboard);
995
+ WINPR_ASSERT(cliprdr);
996
+
997
+ clipboard->context = cliprdr;
998
+ cliprdr->MonitorReady = wlf_cliprdr_monitor_ready;
999
+ cliprdr->ServerCapabilities = wlf_cliprdr_server_capabilities;
1000
+ cliprdr->ServerFormatList = wlf_cliprdr_server_format_list;
1001
+ cliprdr->ServerFormatListResponse = wlf_cliprdr_server_format_list_response;
1002
+ cliprdr->ServerFormatDataRequest = wlf_cliprdr_server_format_data_request;
1003
+ cliprdr->ServerFormatDataResponse = wlf_cliprdr_server_format_data_response;
1004
+
1005
+ return cliprdr_file_context_init(clipboard->file, cliprdr);
1006
+ }
1007
+
1008
+ BOOL wlf_cliprdr_uninit(wfClipboard* clipboard, CliprdrClientContext* cliprdr)
1009
+ {
1010
+ WINPR_ASSERT(clipboard);
1011
+ if (!cliprdr_file_context_uninit(clipboard->file, cliprdr))
1012
+ return FALSE;
1013
+
1014
+ if (cliprdr)
1015
+ cliprdr->custom = NULL;
1016
+
1017
+ return TRUE;
1018
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_cliprdr.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Wayland Clipboard Redirection
4
+ *
5
+ * Copyright 2018 Armin Novak <[email protected]>
6
+ * Copyright 2018 Thincast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #ifndef FREERDP_CLIENT_WAYLAND_CLIPRDR_H
22
+ #define FREERDP_CLIENT_WAYLAND_CLIPRDR_H
23
+
24
+ #include "wlfreerdp.h"
25
+
26
+ #include <freerdp/client/cliprdr.h>
27
+
28
+ wfClipboard* wlf_clipboard_new(wlfContext* wfc);
29
+ void wlf_clipboard_free(wfClipboard* clipboard);
30
+
31
+ BOOL wlf_cliprdr_init(wfClipboard* clipboard, CliprdrClientContext* cliprdr);
32
+ BOOL wlf_cliprdr_uninit(wfClipboard* clipboard, CliprdrClientContext* cliprdr);
33
+
34
+ BOOL wlf_cliprdr_handle_event(wfClipboard* clipboard, const UwacClipboardEvent* event);
35
+
36
+ #endif /* FREERDP_CLIENT_WAYLAND_CLIPRDR_H */
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_disp.c ADDED
@@ -0,0 +1,458 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Wayland Display Control Channel
4
+ *
5
+ * Copyright 2018 Armin Novak <[email protected]>
6
+ * Copyright 2018 Thincast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #include <winpr/sysinfo.h>
22
+ #include <winpr/cast.h>
23
+
24
+ #include "wlf_disp.h"
25
+
26
+ #define TAG CLIENT_TAG("wayland.disp")
27
+
28
+ #define RESIZE_MIN_DELAY 200 /* minimum delay in ms between two resizes */
29
+
30
+ struct s_wlfDispContext
31
+ {
32
+ wlfContext* wlc;
33
+ DispClientContext* disp;
34
+ BOOL haveXRandr;
35
+ int eventBase, errorBase;
36
+ int lastSentWidth, lastSentHeight;
37
+ UINT64 lastSentDate;
38
+ int targetWidth, targetHeight;
39
+ BOOL activated;
40
+ BOOL waitingResize;
41
+ BOOL fullscreen;
42
+ UINT16 lastSentDesktopOrientation;
43
+ UINT32 lastSentDesktopScaleFactor;
44
+ UINT32 lastSentDeviceScaleFactor;
45
+ };
46
+
47
+ static UINT wlf_disp_sendLayout(DispClientContext* disp, const rdpMonitor* monitors,
48
+ size_t nmonitors);
49
+
50
+ static BOOL wlf_disp_settings_changed(wlfDispContext* wlfDisp)
51
+ {
52
+ rdpSettings* settings = NULL;
53
+
54
+ WINPR_ASSERT(wlfDisp);
55
+ WINPR_ASSERT(wlfDisp->wlc);
56
+
57
+ settings = wlfDisp->wlc->common.context.settings;
58
+ WINPR_ASSERT(settings);
59
+
60
+ if (wlfDisp->lastSentWidth != wlfDisp->targetWidth)
61
+ return TRUE;
62
+
63
+ if (wlfDisp->lastSentHeight != wlfDisp->targetHeight)
64
+ return TRUE;
65
+
66
+ if (wlfDisp->lastSentDesktopOrientation !=
67
+ freerdp_settings_get_uint16(settings, FreeRDP_DesktopOrientation))
68
+ return TRUE;
69
+
70
+ if (wlfDisp->lastSentDesktopScaleFactor !=
71
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopScaleFactor))
72
+ return TRUE;
73
+
74
+ if (wlfDisp->lastSentDeviceScaleFactor !=
75
+ freerdp_settings_get_uint32(settings, FreeRDP_DeviceScaleFactor))
76
+ return TRUE;
77
+
78
+ if (wlfDisp->fullscreen != wlfDisp->wlc->fullscreen)
79
+ return TRUE;
80
+
81
+ return FALSE;
82
+ }
83
+
84
+ static BOOL wlf_update_last_sent(wlfDispContext* wlfDisp)
85
+ {
86
+ rdpSettings* settings = NULL;
87
+
88
+ WINPR_ASSERT(wlfDisp);
89
+ WINPR_ASSERT(wlfDisp->wlc);
90
+
91
+ settings = wlfDisp->wlc->common.context.settings;
92
+ WINPR_ASSERT(settings);
93
+
94
+ wlfDisp->lastSentWidth = wlfDisp->targetWidth;
95
+ wlfDisp->lastSentHeight = wlfDisp->targetHeight;
96
+ wlfDisp->lastSentDesktopOrientation =
97
+ freerdp_settings_get_uint16(settings, FreeRDP_DesktopOrientation);
98
+ wlfDisp->lastSentDesktopScaleFactor =
99
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopScaleFactor);
100
+ wlfDisp->lastSentDeviceScaleFactor =
101
+ freerdp_settings_get_uint32(settings, FreeRDP_DeviceScaleFactor);
102
+ wlfDisp->fullscreen = wlfDisp->wlc->fullscreen;
103
+ return TRUE;
104
+ }
105
+
106
+ static BOOL wlf_disp_sendResize(wlfDispContext* wlfDisp)
107
+ {
108
+ DISPLAY_CONTROL_MONITOR_LAYOUT layout;
109
+ wlfContext* wlc = NULL;
110
+ rdpSettings* settings = NULL;
111
+
112
+ if (!wlfDisp || !wlfDisp->wlc)
113
+ return FALSE;
114
+
115
+ wlc = wlfDisp->wlc;
116
+ settings = wlc->common.context.settings;
117
+
118
+ if (!settings)
119
+ return FALSE;
120
+
121
+ if (!wlfDisp->activated || !wlfDisp->disp)
122
+ return TRUE;
123
+
124
+ if (GetTickCount64() - wlfDisp->lastSentDate < RESIZE_MIN_DELAY)
125
+ return TRUE;
126
+
127
+ wlfDisp->lastSentDate = GetTickCount64();
128
+
129
+ if (!wlf_disp_settings_changed(wlfDisp))
130
+ return TRUE;
131
+
132
+ /* TODO: Multimonitor support for wayland
133
+ if (wlc->fullscreen && (freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount > 0))
134
+ {
135
+ if (wlf_disp_sendLayout(wlfDisp->disp, setings->MonitorDefArray,
136
+ freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount) !=
137
+ CHANNEL_RC_OK) return FALSE;
138
+ }
139
+ else
140
+ */
141
+ {
142
+ wlfDisp->waitingResize = TRUE;
143
+ layout.Flags = DISPLAY_CONTROL_MONITOR_PRIMARY;
144
+ layout.Top = layout.Left = 0;
145
+ layout.Width = WINPR_ASSERTING_INT_CAST(uint32_t, wlfDisp->targetWidth);
146
+ layout.Height = WINPR_ASSERTING_INT_CAST(uint32_t, wlfDisp->targetHeight);
147
+ layout.Orientation = freerdp_settings_get_uint16(settings, FreeRDP_DesktopOrientation);
148
+ layout.DesktopScaleFactor =
149
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopScaleFactor);
150
+ layout.DeviceScaleFactor = freerdp_settings_get_uint32(settings, FreeRDP_DeviceScaleFactor);
151
+ layout.PhysicalWidth = WINPR_ASSERTING_INT_CAST(uint32_t, wlfDisp->targetWidth);
152
+ layout.PhysicalHeight = WINPR_ASSERTING_INT_CAST(uint32_t, wlfDisp->targetHeight);
153
+
154
+ if (IFCALLRESULT(CHANNEL_RC_OK, wlfDisp->disp->SendMonitorLayout, wlfDisp->disp, 1,
155
+ &layout) != CHANNEL_RC_OK)
156
+ return FALSE;
157
+ }
158
+ return wlf_update_last_sent(wlfDisp);
159
+ }
160
+
161
+ static BOOL wlf_disp_set_window_resizable(wlfDispContext* wlfDisp)
162
+ {
163
+ #if 0 // TODO
164
+ #endif
165
+ return TRUE;
166
+ }
167
+
168
+ static BOOL wlf_disp_check_context(void* context, wlfContext** ppwlc, wlfDispContext** ppwlfDisp,
169
+ rdpSettings** ppSettings)
170
+ {
171
+ wlfContext* wlc = NULL;
172
+
173
+ if (!context)
174
+ return FALSE;
175
+
176
+ wlc = (wlfContext*)context;
177
+
178
+ if (!(wlc->disp))
179
+ return FALSE;
180
+
181
+ if (!wlc->common.context.settings)
182
+ return FALSE;
183
+
184
+ *ppwlc = wlc;
185
+ *ppwlfDisp = wlc->disp;
186
+ *ppSettings = wlc->common.context.settings;
187
+ return TRUE;
188
+ }
189
+
190
+ static void wlf_disp_OnActivated(void* context, const ActivatedEventArgs* e)
191
+ {
192
+ wlfContext* wlc = NULL;
193
+ wlfDispContext* wlfDisp = NULL;
194
+ rdpSettings* settings = NULL;
195
+
196
+ if (!wlf_disp_check_context(context, &wlc, &wlfDisp, &settings))
197
+ return;
198
+
199
+ wlfDisp->waitingResize = FALSE;
200
+
201
+ if (wlfDisp->activated && !freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
202
+ {
203
+ wlf_disp_set_window_resizable(wlfDisp);
204
+
205
+ if (e->firstActivation)
206
+ return;
207
+
208
+ wlf_disp_sendResize(wlfDisp);
209
+ }
210
+ }
211
+
212
+ static void wlf_disp_OnGraphicsReset(void* context, const GraphicsResetEventArgs* e)
213
+ {
214
+ wlfContext* wlc = NULL;
215
+ wlfDispContext* wlfDisp = NULL;
216
+ rdpSettings* settings = NULL;
217
+
218
+ WINPR_UNUSED(e);
219
+ if (!wlf_disp_check_context(context, &wlc, &wlfDisp, &settings))
220
+ return;
221
+
222
+ wlfDisp->waitingResize = FALSE;
223
+
224
+ if (wlfDisp->activated && !freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
225
+ {
226
+ wlf_disp_set_window_resizable(wlfDisp);
227
+ wlf_disp_sendResize(wlfDisp);
228
+ }
229
+ }
230
+
231
+ static void wlf_disp_OnTimer(void* context, const TimerEventArgs* e)
232
+ {
233
+ wlfContext* wlc = NULL;
234
+ wlfDispContext* wlfDisp = NULL;
235
+ rdpSettings* settings = NULL;
236
+
237
+ WINPR_UNUSED(e);
238
+ if (!wlf_disp_check_context(context, &wlc, &wlfDisp, &settings))
239
+ return;
240
+
241
+ if (!wlfDisp->activated || freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
242
+ return;
243
+
244
+ wlf_disp_sendResize(wlfDisp);
245
+ }
246
+
247
+ wlfDispContext* wlf_disp_new(wlfContext* wlc)
248
+ {
249
+ wlfDispContext* ret = NULL;
250
+ wPubSub* pubSub = NULL;
251
+ rdpSettings* settings = NULL;
252
+
253
+ if (!wlc || !wlc->common.context.settings || !wlc->common.context.pubSub)
254
+ return NULL;
255
+
256
+ settings = wlc->common.context.settings;
257
+ pubSub = wlc->common.context.pubSub;
258
+ ret = calloc(1, sizeof(wlfDispContext));
259
+
260
+ if (!ret)
261
+ return NULL;
262
+
263
+ ret->wlc = wlc;
264
+ ret->lastSentWidth = ret->targetWidth =
265
+ WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth));
266
+ ret->lastSentHeight = ret->targetHeight =
267
+ WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
268
+ PubSub_SubscribeActivated(pubSub, wlf_disp_OnActivated);
269
+ PubSub_SubscribeGraphicsReset(pubSub, wlf_disp_OnGraphicsReset);
270
+ PubSub_SubscribeTimer(pubSub, wlf_disp_OnTimer);
271
+ return ret;
272
+ }
273
+
274
+ void wlf_disp_free(wlfDispContext* disp)
275
+ {
276
+ if (!disp)
277
+ return;
278
+
279
+ if (disp->wlc)
280
+ {
281
+ wPubSub* pubSub = disp->wlc->common.context.pubSub;
282
+ PubSub_UnsubscribeActivated(pubSub, wlf_disp_OnActivated);
283
+ PubSub_UnsubscribeGraphicsReset(pubSub, wlf_disp_OnGraphicsReset);
284
+ PubSub_UnsubscribeTimer(pubSub, wlf_disp_OnTimer);
285
+ }
286
+
287
+ free(disp);
288
+ }
289
+
290
+ UINT wlf_disp_sendLayout(DispClientContext* disp, const rdpMonitor* monitors, size_t nmonitors)
291
+ {
292
+ UINT ret = CHANNEL_RC_OK;
293
+ DISPLAY_CONTROL_MONITOR_LAYOUT* layouts = NULL;
294
+ wlfDispContext* wlfDisp = NULL;
295
+ rdpSettings* settings = NULL;
296
+
297
+ WINPR_ASSERT(disp);
298
+ WINPR_ASSERT(monitors);
299
+ WINPR_ASSERT(nmonitors > 0);
300
+ WINPR_ASSERT(nmonitors <= UINT32_MAX);
301
+
302
+ wlfDisp = (wlfDispContext*)disp->custom;
303
+ WINPR_ASSERT(wlfDisp);
304
+ WINPR_ASSERT(wlfDisp->wlc);
305
+
306
+ settings = wlfDisp->wlc->common.context.settings;
307
+ WINPR_ASSERT(settings);
308
+
309
+ layouts = calloc(nmonitors, sizeof(DISPLAY_CONTROL_MONITOR_LAYOUT));
310
+
311
+ if (!layouts)
312
+ return CHANNEL_RC_NO_MEMORY;
313
+
314
+ for (size_t i = 0; i < nmonitors; i++)
315
+ {
316
+ const rdpMonitor* monitor = &monitors[i];
317
+ DISPLAY_CONTROL_MONITOR_LAYOUT* layout = &layouts[i];
318
+
319
+ layout->Flags = (monitor->is_primary ? DISPLAY_CONTROL_MONITOR_PRIMARY : 0);
320
+ layout->Left = monitor->x;
321
+ layout->Top = monitor->y;
322
+ layout->Width = WINPR_ASSERTING_INT_CAST(UINT32, monitor->width);
323
+ layout->Height = WINPR_ASSERTING_INT_CAST(UINT32, monitor->height);
324
+ layout->Orientation = ORIENTATION_LANDSCAPE;
325
+ layout->PhysicalWidth = monitor->attributes.physicalWidth;
326
+ layout->PhysicalHeight = monitor->attributes.physicalHeight;
327
+
328
+ switch (monitor->attributes.orientation)
329
+ {
330
+ case 90:
331
+ layout->Orientation = ORIENTATION_PORTRAIT;
332
+ break;
333
+
334
+ case 180:
335
+ layout->Orientation = ORIENTATION_LANDSCAPE_FLIPPED;
336
+ break;
337
+
338
+ case 270:
339
+ layout->Orientation = ORIENTATION_PORTRAIT_FLIPPED;
340
+ break;
341
+
342
+ case 0:
343
+ default:
344
+ /* MS-RDPEDISP - 2.2.2.2.1:
345
+ * Orientation (4 bytes): A 32-bit unsigned integer that specifies the
346
+ * orientation of the monitor in degrees. Valid values are 0, 90, 180
347
+ * or 270
348
+ *
349
+ * So we default to ORIENTATION_LANDSCAPE
350
+ */
351
+ layout->Orientation = ORIENTATION_LANDSCAPE;
352
+ break;
353
+ }
354
+
355
+ layout->DesktopScaleFactor =
356
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopScaleFactor);
357
+ layout->DeviceScaleFactor =
358
+ freerdp_settings_get_uint32(settings, FreeRDP_DeviceScaleFactor);
359
+ }
360
+
361
+ ret = IFCALLRESULT(CHANNEL_RC_OK, disp->SendMonitorLayout, disp, (UINT32)nmonitors, layouts);
362
+ free(layouts);
363
+ return ret;
364
+ }
365
+
366
+ BOOL wlf_disp_handle_configure(wlfDispContext* disp, int32_t width, int32_t height)
367
+ {
368
+ if (!disp)
369
+ return FALSE;
370
+
371
+ disp->targetWidth = width;
372
+ disp->targetHeight = height;
373
+ return wlf_disp_sendResize(disp);
374
+ }
375
+
376
+ static UINT wlf_DisplayControlCaps(DispClientContext* disp, UINT32 maxNumMonitors,
377
+ UINT32 maxMonitorAreaFactorA, UINT32 maxMonitorAreaFactorB)
378
+ {
379
+ /* we're called only if dynamic resolution update is activated */
380
+ wlfDispContext* wlfDisp = NULL;
381
+ rdpSettings* settings = NULL;
382
+
383
+ WINPR_ASSERT(disp);
384
+
385
+ wlfDisp = (wlfDispContext*)disp->custom;
386
+ WINPR_ASSERT(wlfDisp);
387
+ WINPR_ASSERT(wlfDisp->wlc);
388
+
389
+ settings = wlfDisp->wlc->common.context.settings;
390
+ WINPR_ASSERT(settings);
391
+
392
+ WLog_DBG(TAG,
393
+ "DisplayControlCapsPdu: MaxNumMonitors: %" PRIu32 " MaxMonitorAreaFactorA: %" PRIu32
394
+ " MaxMonitorAreaFactorB: %" PRIu32 "",
395
+ maxNumMonitors, maxMonitorAreaFactorA, maxMonitorAreaFactorB);
396
+ wlfDisp->activated = TRUE;
397
+
398
+ if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
399
+ return CHANNEL_RC_OK;
400
+
401
+ WLog_DBG(TAG, "DisplayControlCapsPdu: setting the window as resizable");
402
+ return wlf_disp_set_window_resizable(wlfDisp) ? CHANNEL_RC_OK : CHANNEL_RC_NO_MEMORY;
403
+ }
404
+
405
+ BOOL wlf_disp_init(wlfDispContext* wlfDisp, DispClientContext* disp)
406
+ {
407
+ rdpSettings* settings = NULL;
408
+
409
+ if (!wlfDisp || !wlfDisp->wlc || !disp)
410
+ return FALSE;
411
+
412
+ settings = wlfDisp->wlc->common.context.settings;
413
+
414
+ if (!settings)
415
+ return FALSE;
416
+
417
+ wlfDisp->disp = disp;
418
+ disp->custom = (void*)wlfDisp;
419
+
420
+ if (freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate))
421
+ {
422
+ disp->DisplayControlCaps = wlf_DisplayControlCaps;
423
+ }
424
+
425
+ return TRUE;
426
+ }
427
+
428
+ BOOL wlf_disp_uninit(wlfDispContext* wlfDisp, DispClientContext* disp)
429
+ {
430
+ if (!wlfDisp || !disp)
431
+ return FALSE;
432
+
433
+ wlfDisp->disp = NULL;
434
+ return TRUE;
435
+ }
436
+
437
+ int wlf_list_monitors(wlfContext* wlc)
438
+ {
439
+ uint32_t nmonitors = UwacDisplayGetNbOutputs(wlc->display);
440
+
441
+ for (uint32_t i = 0; i < nmonitors; i++)
442
+ {
443
+ const UwacOutput* monitor =
444
+ UwacDisplayGetOutput(wlc->display, WINPR_ASSERTING_INT_CAST(int, i));
445
+ UwacSize resolution;
446
+ UwacPosition pos;
447
+
448
+ if (!monitor)
449
+ continue;
450
+ UwacOutputGetPosition(monitor, &pos);
451
+ UwacOutputGetResolution(monitor, &resolution);
452
+
453
+ printf(" %s [%u] %dx%d\t+%d+%d\n", (i == 0) ? "*" : " ", i, resolution.width,
454
+ resolution.height, pos.x, pos.y);
455
+ }
456
+
457
+ return 0;
458
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_disp.h ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Wayland Display Control Channel
4
+ *
5
+ * Copyright 2018 Armin Novak <[email protected]>
6
+ * Copyright 2018 Thincast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+ #ifndef FREERDP_CLIENT_WAYLAND_DISP_H
21
+ #define FREERDP_CLIENT_WAYLAND_DISP_H
22
+
23
+ #include <freerdp/types.h>
24
+ #include <freerdp/client/disp.h>
25
+
26
+ #include "wlfreerdp.h"
27
+
28
+ FREERDP_API BOOL wlf_disp_init(wlfDispContext* xfDisp, DispClientContext* disp);
29
+ FREERDP_API BOOL wlf_disp_uninit(wlfDispContext* xfDisp, DispClientContext* disp);
30
+
31
+ wlfDispContext* wlf_disp_new(wlfContext* wlc);
32
+ void wlf_disp_free(wlfDispContext* disp);
33
+ BOOL wlf_disp_handle_configure(wlfDispContext* disp, int32_t width, int32_t height);
34
+ void wlf_disp_resized(wlfDispContext* disp);
35
+
36
+ int wlf_list_monitors(wlfContext* wlc);
37
+
38
+ #endif /* FREERDP_CLIENT_WAYLAND_DISP_H */
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_input.c ADDED
@@ -0,0 +1,455 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Wayland Input
4
+ *
5
+ * Copyright 2014 Manuel Bachmann <[email protected]>
6
+ * Copyright 2015 David Fort <[email protected]>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #include <stdlib.h>
22
+ #include <float.h>
23
+
24
+ #include <linux/input.h>
25
+
26
+ #include <winpr/assert.h>
27
+ #include <winpr/cast.h>
28
+
29
+ #include <freerdp/config.h>
30
+ #include <freerdp/locale/keyboard.h>
31
+ #if defined(CHANNEL_RDPEI_CLIENT)
32
+ #include <freerdp/client/rdpei.h>
33
+ #endif
34
+ #include <uwac/uwac.h>
35
+
36
+ #include "wlfreerdp.h"
37
+ #include "wlf_input.h"
38
+
39
+ static BOOL scale_signed_coordinates(rdpContext* context, int32_t* x, int32_t* y,
40
+ BOOL fromLocalToRDP)
41
+ {
42
+ BOOL rc = 0;
43
+ UINT32 ux = 0;
44
+ UINT32 uy = 0;
45
+ WINPR_ASSERT(context);
46
+ WINPR_ASSERT(x);
47
+ WINPR_ASSERT(y);
48
+ WINPR_ASSERT(*x >= 0);
49
+ WINPR_ASSERT(*y >= 0);
50
+
51
+ ux = (UINT32)*x;
52
+ uy = (UINT32)*y;
53
+ rc = wlf_scale_coordinates(context, &ux, &uy, fromLocalToRDP);
54
+ WINPR_ASSERT(ux < INT32_MAX);
55
+ WINPR_ASSERT(uy < INT32_MAX);
56
+ *x = (int32_t)ux;
57
+ *y = (int32_t)uy;
58
+ return rc;
59
+ }
60
+
61
+ BOOL wlf_handle_pointer_enter(freerdp* instance, const UwacPointerEnterLeaveEvent* ev)
62
+ {
63
+ uint32_t x = 0;
64
+ uint32_t y = 0;
65
+ rdpClientContext* cctx = NULL;
66
+
67
+ if (!instance || !ev)
68
+ return FALSE;
69
+
70
+ x = ev->x;
71
+ y = ev->y;
72
+
73
+ if (!wlf_scale_coordinates(instance->context, &x, &y, TRUE))
74
+ return FALSE;
75
+
76
+ cctx = (rdpClientContext*)instance->context;
77
+ return freerdp_client_send_button_event(cctx, FALSE, PTR_FLAGS_MOVE,
78
+ WINPR_ASSERTING_INT_CAST(int, x),
79
+ WINPR_ASSERTING_INT_CAST(int, y));
80
+ }
81
+
82
+ BOOL wlf_handle_pointer_motion(freerdp* instance, const UwacPointerMotionEvent* ev)
83
+ {
84
+ rdpClientContext* cctx = NULL;
85
+
86
+ if (!instance || !ev)
87
+ return FALSE;
88
+
89
+ cctx = (rdpClientContext*)instance->context;
90
+ WINPR_ASSERT(cctx);
91
+
92
+ uint32_t x = ev->x;
93
+ uint32_t y = ev->y;
94
+
95
+ if (!wlf_scale_coordinates(instance->context, &x, &y, TRUE))
96
+ return FALSE;
97
+
98
+ return freerdp_client_send_button_event(cctx, FALSE, PTR_FLAGS_MOVE,
99
+ WINPR_ASSERTING_INT_CAST(int32_t, x),
100
+ WINPR_ASSERTING_INT_CAST(int32_t, y));
101
+ }
102
+
103
+ BOOL wlf_handle_pointer_buttons(freerdp* instance, const UwacPointerButtonEvent* ev)
104
+ {
105
+ rdpClientContext* cctx = NULL;
106
+ UINT16 flags = 0;
107
+ UINT16 xflags = 0;
108
+
109
+ if (!instance || !ev)
110
+ return FALSE;
111
+
112
+ cctx = (rdpClientContext*)instance->context;
113
+ WINPR_ASSERT(cctx);
114
+
115
+ uint32_t x = ev->x;
116
+ uint32_t y = ev->y;
117
+
118
+ if (!wlf_scale_coordinates(instance->context, &x, &y, TRUE))
119
+ return FALSE;
120
+
121
+ if (ev->state == WL_POINTER_BUTTON_STATE_PRESSED)
122
+ {
123
+ flags |= PTR_FLAGS_DOWN;
124
+ xflags |= PTR_XFLAGS_DOWN;
125
+ }
126
+
127
+ switch (ev->button)
128
+ {
129
+ case BTN_LEFT:
130
+ flags |= PTR_FLAGS_BUTTON1;
131
+ break;
132
+
133
+ case BTN_RIGHT:
134
+ flags |= PTR_FLAGS_BUTTON2;
135
+ break;
136
+
137
+ case BTN_MIDDLE:
138
+ flags |= PTR_FLAGS_BUTTON3;
139
+ break;
140
+
141
+ case BTN_SIDE:
142
+ xflags |= PTR_XFLAGS_BUTTON1;
143
+ break;
144
+
145
+ case BTN_EXTRA:
146
+ xflags |= PTR_XFLAGS_BUTTON2;
147
+ break;
148
+
149
+ default:
150
+ return TRUE;
151
+ }
152
+
153
+ const INT32 cx = WINPR_ASSERTING_INT_CAST(int32_t, x);
154
+ const INT32 cy = WINPR_ASSERTING_INT_CAST(int32_t, y);
155
+
156
+ if ((flags & ~PTR_FLAGS_DOWN) != 0)
157
+ return freerdp_client_send_button_event(cctx, FALSE, flags, cx, cy);
158
+
159
+ if ((xflags & ~PTR_XFLAGS_DOWN) != 0)
160
+ return freerdp_client_send_extended_button_event(cctx, FALSE, xflags, cx, cy);
161
+
162
+ return FALSE;
163
+ }
164
+
165
+ BOOL wlf_handle_pointer_axis(freerdp* instance, const UwacPointerAxisEvent* ev)
166
+ {
167
+ wlfContext* context = NULL;
168
+ if (!instance || !instance->context || !ev)
169
+ return FALSE;
170
+
171
+ context = (wlfContext*)instance->context;
172
+ return ArrayList_Append(context->events, ev);
173
+ }
174
+
175
+ BOOL wlf_handle_pointer_axis_discrete(freerdp* instance, const UwacPointerAxisEvent* ev)
176
+ {
177
+ wlfContext* context = NULL;
178
+ if (!instance || !instance->context || !ev)
179
+ return FALSE;
180
+
181
+ context = (wlfContext*)instance->context;
182
+ return ArrayList_Append(context->events, ev);
183
+ }
184
+
185
+ static BOOL wlf_handle_wheel(freerdp* instance, uint32_t x, uint32_t y, uint32_t axis,
186
+ int32_t value)
187
+ {
188
+ rdpClientContext* cctx = NULL;
189
+ UINT16 flags = 0;
190
+ int32_t direction = 0;
191
+ uint32_t avalue = (uint32_t)abs(value);
192
+
193
+ WINPR_ASSERT(instance);
194
+
195
+ cctx = (rdpClientContext*)instance->context;
196
+ WINPR_ASSERT(cctx);
197
+
198
+ if (!wlf_scale_coordinates(instance->context, &x, &y, TRUE))
199
+ return FALSE;
200
+
201
+ direction = value;
202
+ switch (axis)
203
+ {
204
+ case WL_POINTER_AXIS_VERTICAL_SCROLL:
205
+ flags |= PTR_FLAGS_WHEEL;
206
+ if (direction > 0)
207
+ flags |= PTR_FLAGS_WHEEL_NEGATIVE;
208
+ break;
209
+
210
+ case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
211
+ flags |= PTR_FLAGS_HWHEEL;
212
+ if (direction < 0)
213
+ flags |= PTR_FLAGS_WHEEL_NEGATIVE;
214
+ break;
215
+
216
+ default:
217
+ return FALSE;
218
+ }
219
+
220
+ /* Wheel rotation steps:
221
+ *
222
+ * positive: 0 ... 0xFF -> slow ... fast
223
+ * negative: 0 ... 0xFF -> fast ... slow
224
+ */
225
+
226
+ while (avalue > 0)
227
+ {
228
+ const UINT16 cval = (avalue > 0xFF) ? 0xFF : (UINT16)avalue;
229
+ UINT16 cflags = flags | cval;
230
+ /* Convert negative values to 9bit twos complement */
231
+ if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
232
+ cflags = (flags & 0xFF00) | (0x100 - cval);
233
+ if (!freerdp_client_send_wheel_event(cctx, cflags))
234
+ return FALSE;
235
+
236
+ avalue -= cval;
237
+ }
238
+ return TRUE;
239
+ }
240
+
241
+ BOOL wlf_handle_pointer_frame(freerdp* instance, const UwacPointerFrameEvent* ev)
242
+ {
243
+ BOOL success = TRUE;
244
+ BOOL handle = FALSE;
245
+ wlfContext* context = NULL;
246
+ enum wl_pointer_axis_source source = WL_POINTER_AXIS_SOURCE_CONTINUOUS;
247
+
248
+ if (!instance || !ev || !instance->context)
249
+ return FALSE;
250
+
251
+ context = (wlfContext*)instance->context;
252
+
253
+ for (size_t x = 0; x < ArrayList_Count(context->events); x++)
254
+ {
255
+ UwacEvent* cev = ArrayList_GetItem(context->events, x);
256
+ if (!cev)
257
+ continue;
258
+ if (cev->type == UWAC_EVENT_POINTER_SOURCE)
259
+ {
260
+ handle = TRUE;
261
+ source = cev->mouse_source.axis_source;
262
+ }
263
+ }
264
+
265
+ /* We need source events to determine how to interpret the data */
266
+ if (handle)
267
+ {
268
+ for (size_t x = 0; x < ArrayList_Count(context->events); x++)
269
+ {
270
+ UwacEvent* cev = ArrayList_GetItem(context->events, x);
271
+ if (!cev)
272
+ continue;
273
+
274
+ switch (source)
275
+ {
276
+ /* If we have a mouse wheel, just use discrete data */
277
+ case WL_POINTER_AXIS_SOURCE_WHEEL:
278
+ #if defined(WL_POINTER_AXIS_SOURCE_WHEEL_TILT_SINCE_VERSION)
279
+ case WL_POINTER_AXIS_SOURCE_WHEEL_TILT:
280
+ #endif
281
+ if (cev->type == UWAC_EVENT_POINTER_AXIS_DISCRETE)
282
+ {
283
+ /* Get the number of steps, multiply by default step width of 120 */
284
+ int32_t val = cev->mouse_axis.value * 0x78;
285
+ /* No wheel event received, success! */
286
+ if (!wlf_handle_wheel(instance, cev->mouse_axis.x, cev->mouse_axis.y,
287
+ cev->mouse_axis.axis, val))
288
+ success = FALSE;
289
+ }
290
+ break;
291
+ /* If we have a touch pad we get actual data, scale */
292
+ case WL_POINTER_AXIS_SOURCE_FINGER:
293
+ case WL_POINTER_AXIS_SOURCE_CONTINUOUS:
294
+ if (cev->type == UWAC_EVENT_POINTER_AXIS)
295
+ {
296
+ double dval = wl_fixed_to_double(cev->mouse_axis.value);
297
+ int32_t val = (int32_t)(dval * 0x78 / 10.0);
298
+ if (!wlf_handle_wheel(instance, cev->mouse_axis.x, cev->mouse_axis.y,
299
+ cev->mouse_axis.axis, val))
300
+ success = FALSE;
301
+ }
302
+ break;
303
+ default:
304
+ break;
305
+ }
306
+ }
307
+ }
308
+ ArrayList_Clear(context->events);
309
+ return success;
310
+ }
311
+
312
+ BOOL wlf_handle_pointer_source(freerdp* instance, const UwacPointerSourceEvent* ev)
313
+ {
314
+ wlfContext* context = NULL;
315
+ if (!instance || !instance->context || !ev)
316
+ return FALSE;
317
+
318
+ context = (wlfContext*)instance->context;
319
+ return ArrayList_Append(context->events, ev);
320
+ }
321
+
322
+ BOOL wlf_handle_key(freerdp* instance, const UwacKeyEvent* ev)
323
+ {
324
+ if (!instance || !ev)
325
+ return FALSE;
326
+
327
+ WINPR_ASSERT(instance->context);
328
+ wlfContext* ctx = (wlfContext*)instance->context;
329
+ if (freerdp_settings_get_bool(instance->context->settings, FreeRDP_GrabKeyboard) &&
330
+ ev->raw_key == KEY_RIGHTCTRL)
331
+ wlf_handle_ungrab_key(instance, ev);
332
+
333
+ rdpInput* input = instance->context->input;
334
+
335
+ const DWORD vc = GetVirtualKeyCodeFromKeycode(ev->raw_key, WINPR_KEYCODE_TYPE_EVDEV);
336
+ const DWORD sc = GetVirtualScanCodeFromVirtualKeyCode(vc, WINPR_KBD_TYPE_IBM_ENHANCED);
337
+ const DWORD rdp_scancode = freerdp_keyboard_remap_key(ctx->remap_table, sc);
338
+
339
+ if (rdp_scancode == RDP_SCANCODE_UNKNOWN)
340
+ return TRUE;
341
+
342
+ return freerdp_input_send_keyboard_event_ex(input, ev->pressed, ev->repeated, rdp_scancode);
343
+ }
344
+
345
+ BOOL wlf_handle_ungrab_key(freerdp* instance, const UwacKeyEvent* ev)
346
+ {
347
+ wlfContext* context = NULL;
348
+ if (!instance || !instance->context || !ev)
349
+ return FALSE;
350
+
351
+ context = (wlfContext*)instance->context;
352
+
353
+ return UwacSeatInhibitShortcuts(context->seat, false) == UWAC_SUCCESS;
354
+ }
355
+
356
+ BOOL wlf_keyboard_enter(freerdp* instance, const UwacKeyboardEnterLeaveEvent* ev)
357
+ {
358
+ if (!instance || !ev)
359
+ return FALSE;
360
+
361
+ ((wlfContext*)instance->context)->focusing = TRUE;
362
+ return TRUE;
363
+ }
364
+
365
+ BOOL wlf_keyboard_modifiers(freerdp* instance, const UwacKeyboardModifiersEvent* ev)
366
+ {
367
+ rdpInput* input = NULL;
368
+ UINT16 syncFlags = 0;
369
+ wlfContext* wlf = NULL;
370
+
371
+ if (!instance || !ev)
372
+ return FALSE;
373
+
374
+ wlf = (wlfContext*)instance->context;
375
+ WINPR_ASSERT(wlf);
376
+
377
+ input = instance->context->input;
378
+ WINPR_ASSERT(input);
379
+
380
+ syncFlags = 0;
381
+
382
+ if (ev->modifiers & UWAC_MOD_CAPS_MASK)
383
+ syncFlags |= KBD_SYNC_CAPS_LOCK;
384
+ if (ev->modifiers & UWAC_MOD_NUM_MASK)
385
+ syncFlags |= KBD_SYNC_NUM_LOCK;
386
+
387
+ if (!wlf->focusing)
388
+ return TRUE;
389
+
390
+ ((wlfContext*)instance->context)->focusing = FALSE;
391
+
392
+ return freerdp_input_send_focus_in_event(input, syncFlags) &&
393
+ freerdp_client_send_button_event(&wlf->common, FALSE, PTR_FLAGS_MOVE, 0, 0);
394
+ }
395
+
396
+ BOOL wlf_handle_touch_up(freerdp* instance, const UwacTouchUp* ev)
397
+ {
398
+ int32_t x = 0;
399
+ int32_t y = 0;
400
+
401
+ WINPR_ASSERT(instance);
402
+ WINPR_ASSERT(ev);
403
+
404
+ wlfContext* wlf = (wlfContext*)instance->context;
405
+ WINPR_ASSERT(wlf);
406
+
407
+ x = ev->x;
408
+ y = ev->y;
409
+
410
+ if (!scale_signed_coordinates(instance->context, &x, &y, TRUE))
411
+ return FALSE;
412
+
413
+ return freerdp_client_handle_touch(&wlf->common, FREERDP_TOUCH_UP, ev->id, 0, x, y);
414
+ }
415
+
416
+ BOOL wlf_handle_touch_down(freerdp* instance, const UwacTouchDown* ev)
417
+ {
418
+ int32_t x = 0;
419
+ int32_t y = 0;
420
+
421
+ WINPR_ASSERT(instance);
422
+ WINPR_ASSERT(ev);
423
+
424
+ wlfContext* wlf = (wlfContext*)instance->context;
425
+ WINPR_ASSERT(wlf);
426
+
427
+ x = ev->x;
428
+ y = ev->y;
429
+
430
+ if (!scale_signed_coordinates(instance->context, &x, &y, TRUE))
431
+ return FALSE;
432
+
433
+ return freerdp_client_handle_touch(&wlf->common, FREERDP_TOUCH_DOWN, ev->id, 0, x, y);
434
+ }
435
+
436
+ BOOL wlf_handle_touch_motion(freerdp* instance, const UwacTouchMotion* ev)
437
+ {
438
+ int32_t x = 0;
439
+ int32_t y = 0;
440
+
441
+ WINPR_ASSERT(instance);
442
+ WINPR_ASSERT(ev);
443
+
444
+ wlfContext* wlf = (wlfContext*)instance->context;
445
+ WINPR_ASSERT(wlf);
446
+
447
+ x = ev->x;
448
+ y = ev->y;
449
+
450
+ if (!scale_signed_coordinates(instance->context, &x, &y, TRUE))
451
+ return FALSE;
452
+
453
+ return freerdp_client_handle_touch(&wlf->common, FREERDP_TOUCH_MOTION, 0,
454
+ WINPR_ASSERTING_INT_CAST(uint32_t, ev->id), x, y);
455
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_input.h ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Wayland Input
4
+ *
5
+ * Copyright 2014 Manuel Bachmann <[email protected]>
6
+ * Copyright 2015 David Fort <[email protected]>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #ifndef FREERDP_CLIENT_WAYLAND_INPUT_H
22
+ #define FREERDP_CLIENT_WAYLAND_INPUT_H
23
+
24
+ #include <freerdp/freerdp.h>
25
+ #include <freerdp/gdi/gdi.h>
26
+ #include <freerdp/gdi/gfx.h>
27
+ #include <uwac/uwac.h>
28
+
29
+ BOOL wlf_handle_pointer_enter(freerdp* instance, const UwacPointerEnterLeaveEvent* ev);
30
+ BOOL wlf_handle_pointer_motion(freerdp* instance, const UwacPointerMotionEvent* ev);
31
+ BOOL wlf_handle_pointer_buttons(freerdp* instance, const UwacPointerButtonEvent* ev);
32
+ BOOL wlf_handle_pointer_axis(freerdp* instance, const UwacPointerAxisEvent* ev);
33
+ BOOL wlf_handle_pointer_axis_discrete(freerdp* instance, const UwacPointerAxisEvent* ev);
34
+ BOOL wlf_handle_pointer_frame(freerdp* instance, const UwacPointerFrameEvent* ev);
35
+ BOOL wlf_handle_pointer_source(freerdp* instance, const UwacPointerSourceEvent* ev);
36
+ BOOL wlf_handle_touch_up(freerdp* instance, const UwacTouchUp* ev);
37
+ BOOL wlf_handle_touch_down(freerdp* instance, const UwacTouchDown* ev);
38
+ BOOL wlf_handle_touch_motion(freerdp* instance, const UwacTouchMotion* ev);
39
+
40
+ BOOL wlf_handle_key(freerdp* instance, const UwacKeyEvent* ev);
41
+ BOOL wlf_handle_ungrab_key(freerdp* instance, const UwacKeyEvent* ev);
42
+ BOOL wlf_keyboard_enter(freerdp* instance, const UwacKeyboardEnterLeaveEvent* ev);
43
+ BOOL wlf_keyboard_modifiers(freerdp* instance, const UwacKeyboardModifiersEvent* ev);
44
+
45
+ #endif /* FREERDP_CLIENT_WAYLAND_INPUT_H */
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_pointer.c ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Wayland Mouse Pointer
4
+ *
5
+ * Copyright 2019 Armin Novak <[email protected]>
6
+ * Copyright 2019 Thincast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #include <freerdp/config.h>
22
+
23
+ #include "wlf_pointer.h"
24
+ #include "wlfreerdp.h"
25
+
26
+ #define TAG CLIENT_TAG("wayland.pointer")
27
+
28
+ typedef struct
29
+ {
30
+ rdpPointer pointer;
31
+ size_t size;
32
+ void* data;
33
+ } wlfPointer;
34
+
35
+ static BOOL wlf_Pointer_New(rdpContext* context, rdpPointer* pointer)
36
+ {
37
+ wlfPointer* ptr = (wlfPointer*)pointer;
38
+
39
+ if (!ptr)
40
+ return FALSE;
41
+
42
+ ptr->size = 4ULL * pointer->width * pointer->height;
43
+ ptr->data = winpr_aligned_malloc(ptr->size, 16);
44
+
45
+ if (!ptr->data)
46
+ return FALSE;
47
+
48
+ if (!freerdp_image_copy_from_pointer_data(
49
+ ptr->data, PIXEL_FORMAT_BGRA32, 0, 0, 0, pointer->width, pointer->height,
50
+ pointer->xorMaskData, pointer->lengthXorMask, pointer->andMaskData,
51
+ pointer->lengthAndMask, pointer->xorBpp, &context->gdi->palette))
52
+ {
53
+ winpr_aligned_free(ptr->data);
54
+ return FALSE;
55
+ }
56
+
57
+ return TRUE;
58
+ }
59
+
60
+ static void wlf_Pointer_Free(rdpContext* context, rdpPointer* pointer)
61
+ {
62
+ wlfPointer* ptr = (wlfPointer*)pointer;
63
+ WINPR_UNUSED(context);
64
+
65
+ if (ptr)
66
+ winpr_aligned_free(ptr->data);
67
+ }
68
+
69
+ static BOOL wlf_Pointer_Set(rdpContext* context, rdpPointer* pointer)
70
+ {
71
+ wlfContext* wlf = (wlfContext*)context;
72
+ wlfPointer* ptr = (wlfPointer*)pointer;
73
+ void* data = NULL;
74
+ UINT32 w = 0;
75
+ UINT32 h = 0;
76
+ UINT32 x = 0;
77
+ UINT32 y = 0;
78
+ size_t size = 0;
79
+ UwacReturnCode rc = UWAC_ERROR_INTERNAL;
80
+ BOOL res = FALSE;
81
+ RECTANGLE_16 area;
82
+
83
+ if (!wlf || !wlf->seat)
84
+ return FALSE;
85
+
86
+ x = pointer->xPos;
87
+ y = pointer->yPos;
88
+ w = pointer->width;
89
+ h = pointer->height;
90
+
91
+ if (!wlf_scale_coordinates(context, &x, &y, FALSE) ||
92
+ !wlf_scale_coordinates(context, &w, &h, FALSE))
93
+ return FALSE;
94
+
95
+ size = 4ULL * w * h;
96
+ data = malloc(size);
97
+
98
+ if (!data)
99
+ return FALSE;
100
+
101
+ area.top = 0;
102
+ area.left = 0;
103
+ area.right = (UINT16)pointer->width;
104
+ area.bottom = (UINT16)pointer->height;
105
+
106
+ if (!wlf_copy_image(ptr->data, 4ULL * pointer->width, pointer->width, pointer->height, data,
107
+ 4ULL * w, w, h, &area,
108
+ freerdp_settings_get_bool(context->settings, FreeRDP_SmartSizing)))
109
+ goto fail;
110
+
111
+ rc = UwacSeatSetMouseCursor(wlf->seat, data, size, w, h, x, y);
112
+
113
+ if (rc == UWAC_SUCCESS)
114
+ res = TRUE;
115
+
116
+ fail:
117
+ free(data);
118
+ return res;
119
+ }
120
+
121
+ static BOOL wlf_Pointer_SetNull(rdpContext* context)
122
+ {
123
+ wlfContext* wlf = (wlfContext*)context;
124
+
125
+ if (!wlf || !wlf->seat)
126
+ return FALSE;
127
+
128
+ if (UwacSeatSetMouseCursor(wlf->seat, NULL, 0, 0, 0, 0, 0) != UWAC_SUCCESS)
129
+ return FALSE;
130
+
131
+ return TRUE;
132
+ }
133
+
134
+ static BOOL wlf_Pointer_SetDefault(rdpContext* context)
135
+ {
136
+ wlfContext* wlf = (wlfContext*)context;
137
+
138
+ if (!wlf || !wlf->seat)
139
+ return FALSE;
140
+
141
+ if (UwacSeatSetMouseCursor(wlf->seat, NULL, 1, 0, 0, 0, 0) != UWAC_SUCCESS)
142
+ return FALSE;
143
+
144
+ return TRUE;
145
+ }
146
+
147
+ static BOOL wlf_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
148
+ {
149
+ // TODO
150
+ WLog_WARN(TAG, "not implemented");
151
+ return TRUE;
152
+ }
153
+
154
+ BOOL wlf_register_pointer(rdpGraphics* graphics)
155
+ {
156
+ rdpPointer pointer = { 0 };
157
+
158
+ pointer.size = sizeof(wlfPointer);
159
+ pointer.New = wlf_Pointer_New;
160
+ pointer.Free = wlf_Pointer_Free;
161
+ pointer.Set = wlf_Pointer_Set;
162
+ pointer.SetNull = wlf_Pointer_SetNull;
163
+ pointer.SetDefault = wlf_Pointer_SetDefault;
164
+ pointer.SetPosition = wlf_Pointer_SetPosition;
165
+ graphics_register_pointer(graphics, &pointer);
166
+ return TRUE;
167
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlf_pointer.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Wayland Mouse Pointer
4
+ *
5
+ * Copyright 2019 Armin Novak <[email protected]>
6
+ * Copyright 2019 Thincast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #ifndef FREERDP_CLIENT_WAYLAND_POINTER_H
22
+ #define FREERDP_CLIENT_WAYLAND_POINTER_H
23
+
24
+ #include <freerdp/graphics.h>
25
+
26
+ BOOL wlf_register_pointer(rdpGraphics* graphics);
27
+
28
+ #endif /* FREERDP_CLIENT_WAYLAND_POINTER_H */
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlfreerdp.1.in ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .de URL
2
+ \\$2 \(laURL: \\$1 \(ra\\$3
3
+ ..
4
+ .if \n[.g] .mso www.tmac
5
+ .TH @MANPAGE_NAME@ 1 2017-01-12 "@FREERDP_VERSION_FULL@" "FreeRDP"
6
+ .SH NAME
7
+ @MANPAGE_NAME@ \- FreeRDP wayland client
8
+ .SH SYNOPSIS
9
+ .B @MANPAGE_NAME@
10
+ [file]
11
+ [\fIdefault_client_options\fP]
12
+ [\fB/v\fP:<server>[:port]]
13
+ [\fB/version\fP]
14
+ [\fB/help\fP]
15
+ .SH DESCRIPTION
16
+ .B @MANPAGE_NAME@
17
+ is a wayland Remote Desktop Protocol (RDP) client which is part of the FreeRDP project. A RDP server is built-in to many editions of Windows.. Alternative servers included ogon, gnome-remote-desktop, xrdp and VRDP (VirtualBox).
18
+ .SH OPTIONS
19
+ The wayland client also supports a lot of the \fIdefault client options\fP which are not described here. For details on those see the xfreerdp(1) man page.
20
+ .IP \fB/v:\fP\fI<server>[:port]\fP
21
+ The server hostname or IP, and optionally the port, to connect to.
22
+ .IP /version
23
+ Print the version and exit.
24
+ .IP /help
25
+ Print the help and exit.
26
+ .SH EXIT STATUS
27
+ .TP
28
+ .B 0
29
+ Successful program execution.
30
+ .TP
31
+ .B not 0
32
+ On failure.
33
+
34
+ .SH SEE ALSO
35
+ xfreerdp(1) wlog(7)
36
+
37
+ .SH AUTHOR
38
+ FreeRDP <[email protected]>
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlfreerdp.c ADDED
@@ -0,0 +1,815 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Wayland Client
4
+ *
5
+ * Copyright 2014 Manuel Bachmann <[email protected]>
6
+ * Copyright 2016 Thincast Technologies GmbH
7
+ * Copyright 2016 Armin Novak <[email protected]>
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+
22
+ #include <math.h>
23
+ #include <stdio.h>
24
+ #include <errno.h>
25
+ #include <locale.h>
26
+ #include <float.h>
27
+
28
+ #include <winpr/sysinfo.h>
29
+ #include <winpr/cast.h>
30
+
31
+ #include <freerdp/client/cmdline.h>
32
+ #include <freerdp/channels/channels.h>
33
+ #include <freerdp/gdi/gdi.h>
34
+ #include <freerdp/client.h>
35
+ #include <freerdp/utils/signal.h>
36
+ #include <freerdp/locale/keyboard.h>
37
+
38
+ #include <linux/input.h>
39
+
40
+ #include <uwac/uwac.h>
41
+
42
+ #include "wlfreerdp.h"
43
+ #include "wlf_input.h"
44
+ #include "wlf_cliprdr.h"
45
+ #include "wlf_disp.h"
46
+ #include "wlf_channels.h"
47
+ #include "wlf_pointer.h"
48
+
49
+ #define TAG CLIENT_TAG("wayland")
50
+
51
+ static BOOL wl_update_buffer(wlfContext* context_w, INT32 ix, INT32 iy, INT32 iw, INT32 ih)
52
+ {
53
+ BOOL res = FALSE;
54
+ rdpGdi* gdi = NULL;
55
+ char* data = NULL;
56
+ UwacSize geometry = { 0 };
57
+ size_t stride = 0;
58
+ UwacReturnCode rc = UWAC_ERROR_INTERNAL;
59
+ RECTANGLE_16 area = { 0 };
60
+
61
+ if (!context_w)
62
+ return FALSE;
63
+
64
+ if ((ix < 0) || (iy < 0) || (iw < 0) || (ih < 0))
65
+ return FALSE;
66
+
67
+ EnterCriticalSection(&context_w->critical);
68
+ UINT32 x = WINPR_ASSERTING_INT_CAST(UINT16, ix);
69
+ UINT32 y = WINPR_ASSERTING_INT_CAST(UINT16, iy);
70
+ UINT32 w = WINPR_ASSERTING_INT_CAST(UINT16, iw);
71
+ UINT32 h = WINPR_ASSERTING_INT_CAST(UINT16, ih);
72
+ rc = UwacWindowGetDrawingBufferGeometry(context_w->window, &geometry, &stride);
73
+ data = UwacWindowGetDrawingBuffer(context_w->window);
74
+
75
+ if (!data || (rc != UWAC_SUCCESS))
76
+ goto fail;
77
+
78
+ gdi = context_w->common.context.gdi;
79
+
80
+ if (!gdi)
81
+ goto fail;
82
+
83
+ /* Ignore output if the surface size does not match. */
84
+ if (((INT64)x > geometry.width) || ((INT64)y > geometry.height))
85
+ {
86
+ res = TRUE;
87
+ goto fail;
88
+ }
89
+
90
+ area.left = WINPR_ASSERTING_INT_CAST(UINT16, x);
91
+ area.top = WINPR_ASSERTING_INT_CAST(UINT16, y);
92
+ area.right = WINPR_ASSERTING_INT_CAST(UINT16, x + w);
93
+ area.bottom = WINPR_ASSERTING_INT_CAST(UINT16, y + h);
94
+
95
+ if (!wlf_copy_image(
96
+ gdi->primary_buffer, gdi->stride, WINPR_ASSERTING_INT_CAST(size_t, gdi->width),
97
+ WINPR_ASSERTING_INT_CAST(size_t, gdi->height), data, stride,
98
+ WINPR_ASSERTING_INT_CAST(size_t, geometry.width),
99
+ WINPR_ASSERTING_INT_CAST(size_t, geometry.height), &area,
100
+ freerdp_settings_get_bool(context_w->common.context.settings, FreeRDP_SmartSizing)))
101
+ goto fail;
102
+
103
+ if (!wlf_scale_coordinates(&context_w->common.context, &x, &y, FALSE))
104
+ goto fail;
105
+
106
+ if (!wlf_scale_coordinates(&context_w->common.context, &w, &h, FALSE))
107
+ goto fail;
108
+
109
+ if (UwacWindowAddDamage(context_w->window, x, y, w, h) != UWAC_SUCCESS)
110
+ goto fail;
111
+
112
+ if (UwacWindowSubmitBuffer(context_w->window, false) != UWAC_SUCCESS)
113
+ goto fail;
114
+
115
+ res = TRUE;
116
+ fail:
117
+ LeaveCriticalSection(&context_w->critical);
118
+ return res;
119
+ }
120
+
121
+ static BOOL wl_end_paint(rdpContext* context)
122
+ {
123
+ rdpGdi* gdi = NULL;
124
+ wlfContext* context_w = NULL;
125
+ INT32 x = 0;
126
+ INT32 y = 0;
127
+ INT32 w = 0;
128
+ INT32 h = 0;
129
+
130
+ if (!context || !context->gdi || !context->gdi->primary)
131
+ return FALSE;
132
+
133
+ gdi = context->gdi;
134
+
135
+ if (gdi->primary->hdc->hwnd->invalid->null)
136
+ return TRUE;
137
+
138
+ x = gdi->primary->hdc->hwnd->invalid->x;
139
+ y = gdi->primary->hdc->hwnd->invalid->y;
140
+ w = gdi->primary->hdc->hwnd->invalid->w;
141
+ h = gdi->primary->hdc->hwnd->invalid->h;
142
+ context_w = (wlfContext*)context;
143
+ if (!wl_update_buffer(context_w, x, y, w, h))
144
+ {
145
+ return FALSE;
146
+ }
147
+
148
+ gdi->primary->hdc->hwnd->invalid->null = TRUE;
149
+ gdi->primary->hdc->hwnd->ninvalid = 0;
150
+ return TRUE;
151
+ }
152
+
153
+ static BOOL wl_refresh_display(wlfContext* context)
154
+ {
155
+ rdpGdi* gdi = NULL;
156
+
157
+ if (!context || !context->common.context.gdi)
158
+ return FALSE;
159
+
160
+ gdi = context->common.context.gdi;
161
+ return wl_update_buffer(context, 0, 0, gdi->width, gdi->height);
162
+ }
163
+
164
+ static BOOL wl_resize_display(rdpContext* context)
165
+ {
166
+ wlfContext* wlc = (wlfContext*)context;
167
+ rdpGdi* gdi = context->gdi;
168
+ rdpSettings* settings = context->settings;
169
+
170
+ if (!gdi_resize(gdi, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
171
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)))
172
+ return FALSE;
173
+
174
+ return wl_refresh_display(wlc);
175
+ }
176
+
177
+ static BOOL wl_pre_connect(freerdp* instance)
178
+ {
179
+ rdpSettings* settings = NULL;
180
+ wlfContext* context = NULL;
181
+ const UwacOutput* output = NULL;
182
+ UwacSize resolution;
183
+
184
+ if (!instance)
185
+ return FALSE;
186
+
187
+ context = (wlfContext*)instance->context;
188
+ WINPR_ASSERT(context);
189
+
190
+ settings = instance->context->settings;
191
+ WINPR_ASSERT(settings);
192
+
193
+ if (!freerdp_settings_set_bool(settings, FreeRDP_CertificateCallbackPreferPEM, TRUE))
194
+ return FALSE;
195
+
196
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMajorType, OSMAJORTYPE_UNIX))
197
+ return FALSE;
198
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_NATIVE_WAYLAND))
199
+ return FALSE;
200
+ PubSub_SubscribeChannelConnected(instance->context->pubSub, wlf_OnChannelConnectedEventHandler);
201
+ PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
202
+ wlf_OnChannelDisconnectedEventHandler);
203
+
204
+ if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
205
+ {
206
+ // Use the resolution of the first display output
207
+ output = UwacDisplayGetOutput(context->display, 0);
208
+
209
+ if ((output != NULL) && (UwacOutputGetResolution(output, &resolution) == UWAC_SUCCESS))
210
+ {
211
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth,
212
+ (UINT32)resolution.width))
213
+ return FALSE;
214
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight,
215
+ (UINT32)resolution.height))
216
+ return FALSE;
217
+ }
218
+ else
219
+ {
220
+ WLog_WARN(TAG, "Failed to get output resolution! Check your display settings");
221
+ }
222
+ }
223
+
224
+ return TRUE;
225
+ }
226
+
227
+ static BOOL wl_post_connect(freerdp* instance)
228
+ {
229
+ if (!instance || !instance->context)
230
+ return FALSE;
231
+
232
+ wlfContext* context = (wlfContext*)instance->context;
233
+ WINPR_ASSERT(context);
234
+
235
+ rdpSettings* settings = instance->context->settings;
236
+ WINPR_ASSERT(settings);
237
+
238
+ const char* title = "FreeRDP";
239
+ const char* wtitle = freerdp_settings_get_string(settings, FreeRDP_WindowTitle);
240
+ if (wtitle)
241
+ title = wtitle;
242
+
243
+ const char* app_id = "wlfreerdp";
244
+ const char* wmclass = freerdp_settings_get_string(settings, FreeRDP_WmClass);
245
+ if (wmclass)
246
+ app_id = wmclass;
247
+
248
+ if (!gdi_init(instance, PIXEL_FORMAT_BGRA32))
249
+ return FALSE;
250
+
251
+ rdpGdi* gdi = instance->context->gdi;
252
+
253
+ if (!gdi || (gdi->width < 0) || (gdi->height < 0))
254
+ return FALSE;
255
+
256
+ if (!wlf_register_pointer(instance->context->graphics))
257
+ return FALSE;
258
+
259
+ UINT32 w = (UINT32)gdi->width;
260
+ UINT32 h = (UINT32)gdi->height;
261
+
262
+ if (freerdp_settings_get_bool(settings, FreeRDP_SmartSizing) && !context->fullscreen)
263
+ {
264
+ const UINT32 sw = freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingWidth);
265
+ if (sw > 0)
266
+ w = sw;
267
+
268
+ const UINT32 sh = freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingHeight);
269
+ if (sh > 0)
270
+ h = sh;
271
+ }
272
+
273
+ context->window = UwacCreateWindowShm(context->display, w, h, WL_SHM_FORMAT_XRGB8888);
274
+
275
+ if (!context->window)
276
+ return FALSE;
277
+
278
+ UwacWindowSetFullscreenState(
279
+ context->window, NULL,
280
+ freerdp_settings_get_bool(instance->context->settings, FreeRDP_Fullscreen));
281
+ UwacWindowSetTitle(context->window, title);
282
+ UwacWindowSetAppId(context->window, app_id);
283
+ UwacWindowSetOpaqueRegion(context->window, 0, 0, w, h);
284
+ instance->context->update->EndPaint = wl_end_paint;
285
+ instance->context->update->DesktopResize = wl_resize_display;
286
+ const char* KeyboardRemappingList =
287
+ freerdp_settings_get_string(instance->context->settings, FreeRDP_KeyboardRemappingList);
288
+
289
+ context->remap_table = freerdp_keyboard_remap_string_to_list(KeyboardRemappingList);
290
+ if (!context->remap_table)
291
+ return FALSE;
292
+
293
+ if (!(context->disp = wlf_disp_new(context)))
294
+ return FALSE;
295
+
296
+ context->clipboard = wlf_clipboard_new(context);
297
+
298
+ if (!context->clipboard)
299
+ return FALSE;
300
+
301
+ return wl_refresh_display(context);
302
+ }
303
+
304
+ static void wl_post_disconnect(freerdp* instance)
305
+ {
306
+ if (!instance)
307
+ return;
308
+
309
+ if (!instance->context)
310
+ return;
311
+
312
+ wlfContext* context = (wlfContext*)instance->context;
313
+ gdi_free(instance);
314
+ wlf_clipboard_free(context->clipboard);
315
+ wlf_disp_free(context->disp);
316
+
317
+ if (context->window)
318
+ UwacDestroyWindow(&context->window);
319
+ freerdp_keyboard_remap_free(context->remap_table);
320
+ context->remap_table = NULL;
321
+ }
322
+
323
+ static BOOL handle_uwac_events(freerdp* instance, UwacDisplay* display)
324
+ {
325
+ UwacEvent event;
326
+ wlfContext* context = NULL;
327
+
328
+ if (UwacDisplayDispatch(display, 1) < 0)
329
+ return FALSE;
330
+
331
+ context = (wlfContext*)instance->context;
332
+
333
+ while (UwacHasEvent(display))
334
+ {
335
+ if (UwacNextEvent(display, &event) != UWAC_SUCCESS)
336
+ return FALSE;
337
+
338
+ /*printf("UWAC event type %d\n", event.type);*/
339
+ switch (event.type)
340
+ {
341
+ case UWAC_EVENT_NEW_SEAT:
342
+ context->seat = event.seat_new.seat;
343
+ break;
344
+
345
+ case UWAC_EVENT_REMOVED_SEAT:
346
+ context->seat = NULL;
347
+ break;
348
+
349
+ case UWAC_EVENT_FRAME_DONE:
350
+ {
351
+ EnterCriticalSection(&context->critical);
352
+ UwacReturnCode r = UwacWindowSubmitBuffer(context->window, false);
353
+ LeaveCriticalSection(&context->critical);
354
+ if (r != UWAC_SUCCESS)
355
+ return FALSE;
356
+ }
357
+ break;
358
+
359
+ case UWAC_EVENT_POINTER_ENTER:
360
+ if (!wlf_handle_pointer_enter(instance, &event.mouse_enter_leave))
361
+ return FALSE;
362
+
363
+ break;
364
+
365
+ case UWAC_EVENT_POINTER_MOTION:
366
+ if (!wlf_handle_pointer_motion(instance, &event.mouse_motion))
367
+ return FALSE;
368
+
369
+ break;
370
+
371
+ case UWAC_EVENT_POINTER_BUTTONS:
372
+ if (!wlf_handle_pointer_buttons(instance, &event.mouse_button))
373
+ return FALSE;
374
+
375
+ break;
376
+
377
+ case UWAC_EVENT_POINTER_AXIS:
378
+ if (!wlf_handle_pointer_axis(instance, &event.mouse_axis))
379
+ return FALSE;
380
+ break;
381
+
382
+ case UWAC_EVENT_POINTER_AXIS_DISCRETE:
383
+ if (!wlf_handle_pointer_axis_discrete(instance, &event.mouse_axis))
384
+ return FALSE;
385
+ break;
386
+
387
+ case UWAC_EVENT_POINTER_FRAME:
388
+ if (!wlf_handle_pointer_frame(instance, &event.mouse_frame))
389
+ return FALSE;
390
+ break;
391
+ case UWAC_EVENT_POINTER_SOURCE:
392
+ if (!wlf_handle_pointer_source(instance, &event.mouse_source))
393
+ return FALSE;
394
+ break;
395
+
396
+ case UWAC_EVENT_KEY:
397
+ if (!wlf_handle_key(instance, &event.key))
398
+ return FALSE;
399
+
400
+ break;
401
+
402
+ case UWAC_EVENT_TOUCH_UP:
403
+ if (!wlf_handle_touch_up(instance, &event.touchUp))
404
+ return FALSE;
405
+
406
+ break;
407
+
408
+ case UWAC_EVENT_TOUCH_DOWN:
409
+ if (!wlf_handle_touch_down(instance, &event.touchDown))
410
+ return FALSE;
411
+
412
+ break;
413
+
414
+ case UWAC_EVENT_TOUCH_MOTION:
415
+ if (!wlf_handle_touch_motion(instance, &event.touchMotion))
416
+ return FALSE;
417
+
418
+ break;
419
+
420
+ case UWAC_EVENT_KEYBOARD_ENTER:
421
+ if (freerdp_settings_get_bool(instance->context->settings, FreeRDP_GrabKeyboard))
422
+ UwacSeatInhibitShortcuts(event.keyboard_enter_leave.seat, true);
423
+
424
+ if (!wlf_keyboard_enter(instance, &event.keyboard_enter_leave))
425
+ return FALSE;
426
+
427
+ break;
428
+
429
+ case UWAC_EVENT_KEYBOARD_MODIFIERS:
430
+ if (!wlf_keyboard_modifiers(instance, &event.keyboard_modifiers))
431
+ return FALSE;
432
+
433
+ break;
434
+
435
+ case UWAC_EVENT_CONFIGURE:
436
+ if (!wlf_disp_handle_configure(context->disp, event.configure.width,
437
+ event.configure.height))
438
+ return FALSE;
439
+
440
+ if (!wl_refresh_display(context))
441
+ return FALSE;
442
+
443
+ break;
444
+
445
+ case UWAC_EVENT_CLIPBOARD_AVAILABLE:
446
+ case UWAC_EVENT_CLIPBOARD_OFFER:
447
+ case UWAC_EVENT_CLIPBOARD_SELECT:
448
+ if (!wlf_cliprdr_handle_event(context->clipboard, &event.clipboard))
449
+ return FALSE;
450
+
451
+ break;
452
+
453
+ case UWAC_EVENT_CLOSE:
454
+ context->closed = TRUE;
455
+
456
+ break;
457
+
458
+ default:
459
+ break;
460
+ }
461
+ }
462
+
463
+ return TRUE;
464
+ }
465
+
466
+ static BOOL handle_window_events(freerdp* instance)
467
+ {
468
+ if (!instance)
469
+ return FALSE;
470
+
471
+ return TRUE;
472
+ }
473
+
474
+ static int wlfreerdp_run(freerdp* instance)
475
+ {
476
+ wlfContext* context = NULL;
477
+ HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
478
+ DWORD status = WAIT_ABANDONED;
479
+ HANDLE timer = NULL;
480
+ LARGE_INTEGER due = { 0 };
481
+
482
+ TimerEventArgs timerEvent;
483
+ EventArgsInit(&timerEvent, "xfreerdp");
484
+
485
+ if (!instance)
486
+ return -1;
487
+
488
+ context = (wlfContext*)instance->context;
489
+
490
+ if (!context)
491
+ return -1;
492
+
493
+ if (!freerdp_connect(instance))
494
+ {
495
+ WLog_Print(context->log, WLOG_ERROR, "Failed to connect");
496
+ return -1;
497
+ }
498
+
499
+ timer = CreateWaitableTimerA(NULL, FALSE, "mainloop-periodic-timer");
500
+
501
+ if (!timer)
502
+ {
503
+ WLog_ERR(TAG, "failed to create timer");
504
+ goto disconnect;
505
+ }
506
+
507
+ due.QuadPart = 0;
508
+
509
+ if (!SetWaitableTimer(timer, &due, 20, NULL, NULL, FALSE))
510
+ {
511
+ goto disconnect;
512
+ }
513
+
514
+ while (!freerdp_shall_disconnect_context(instance->context))
515
+ {
516
+ DWORD count = 0;
517
+ handles[count++] = timer;
518
+ handles[count++] = context->displayHandle;
519
+ count += freerdp_get_event_handles(instance->context, &handles[count],
520
+ ARRAYSIZE(handles) - count);
521
+
522
+ if (count <= 2)
523
+ {
524
+ WLog_Print(context->log, WLOG_ERROR, "Failed to get FreeRDP file descriptor");
525
+ break;
526
+ }
527
+
528
+ status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
529
+
530
+ if (WAIT_FAILED == status)
531
+ {
532
+ WLog_Print(context->log, WLOG_ERROR, "WaitForMultipleObjects failed");
533
+ break;
534
+ }
535
+
536
+ if (!handle_uwac_events(instance, context->display))
537
+ {
538
+ WLog_Print(context->log, WLOG_ERROR, "error handling UWAC events");
539
+ break;
540
+ }
541
+
542
+ if (context->closed)
543
+ {
544
+ WLog_Print(context->log, WLOG_INFO, "Closed from Wayland");
545
+ break;
546
+ }
547
+
548
+ if (freerdp_check_event_handles(instance->context) != TRUE)
549
+ {
550
+ if (client_auto_reconnect_ex(instance, handle_window_events))
551
+ continue;
552
+ else
553
+ {
554
+ /*
555
+ * Indicate an unsuccessful connection attempt if reconnect
556
+ * did not succeed and no other error was specified.
557
+ */
558
+ if (freerdp_error_info(instance) == 0)
559
+ status = 42;
560
+ }
561
+
562
+ if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_SUCCESS)
563
+ WLog_Print(context->log, WLOG_ERROR, "Failed to check FreeRDP file descriptor");
564
+
565
+ break;
566
+ }
567
+
568
+ if ((status != WAIT_TIMEOUT) && (status == WAIT_OBJECT_0))
569
+ {
570
+ timerEvent.now = GetTickCount64();
571
+ PubSub_OnTimer(context->common.context.pubSub, context, &timerEvent);
572
+ }
573
+ }
574
+
575
+ disconnect:
576
+ if (timer)
577
+ (void)CloseHandle(timer);
578
+ freerdp_disconnect(instance);
579
+ return WINPR_ASSERTING_INT_CAST(int, status);
580
+ }
581
+
582
+ static BOOL wlf_client_global_init(void)
583
+ {
584
+ // NOLINTNEXTLINE(concurrency-mt-unsafe)
585
+ (void)setlocale(LC_ALL, "");
586
+
587
+ if (freerdp_handle_signals() != 0)
588
+ return FALSE;
589
+
590
+ return TRUE;
591
+ }
592
+
593
+ static void wlf_client_global_uninit(void)
594
+ {
595
+ }
596
+
597
+ static int wlf_logon_error_info(freerdp* instance, UINT32 data, UINT32 type)
598
+ {
599
+ wlfContext* wlf = NULL;
600
+ const char* str_data = freerdp_get_logon_error_info_data(data);
601
+ const char* str_type = freerdp_get_logon_error_info_type(type);
602
+
603
+ if (!instance || !instance->context)
604
+ return -1;
605
+
606
+ wlf = (wlfContext*)instance->context;
607
+ WLog_Print(wlf->log, WLOG_INFO, "Logon Error Info %s [%s]", str_data, str_type);
608
+ return 1;
609
+ }
610
+
611
+ static void wlf_client_free(freerdp* instance, rdpContext* context)
612
+ {
613
+ wlfContext* wlf = (wlfContext*)instance->context;
614
+
615
+ if (!context)
616
+ return;
617
+
618
+ if (wlf->display)
619
+ UwacCloseDisplay(&wlf->display);
620
+
621
+ if (wlf->displayHandle)
622
+ (void)CloseHandle(wlf->displayHandle);
623
+ ArrayList_Free(wlf->events);
624
+ DeleteCriticalSection(&wlf->critical);
625
+ }
626
+
627
+ static void* uwac_event_clone(const void* val)
628
+ {
629
+ UwacEvent* copy = NULL;
630
+ const UwacEvent* ev = (const UwacEvent*)val;
631
+
632
+ copy = calloc(1, sizeof(UwacEvent));
633
+ if (!copy)
634
+ return NULL;
635
+ *copy = *ev;
636
+ return copy;
637
+ }
638
+
639
+ static BOOL wlf_client_new(freerdp* instance, rdpContext* context)
640
+ {
641
+ wObject* obj = NULL;
642
+ UwacReturnCode status = UWAC_ERROR_INTERNAL;
643
+ wlfContext* wfl = (wlfContext*)context;
644
+
645
+ if (!instance || !context)
646
+ return FALSE;
647
+
648
+ instance->PreConnect = wl_pre_connect;
649
+ instance->PostConnect = wl_post_connect;
650
+ instance->PostDisconnect = wl_post_disconnect;
651
+ instance->LogonErrorInfo = wlf_logon_error_info;
652
+ wfl->log = WLog_Get(TAG);
653
+ wfl->display = UwacOpenDisplay(NULL, &status);
654
+
655
+ if (!wfl->display || (status != UWAC_SUCCESS) || !wfl->log)
656
+ return FALSE;
657
+
658
+ wfl->displayHandle = CreateFileDescriptorEvent(NULL, FALSE, FALSE,
659
+ UwacDisplayGetFd(wfl->display), WINPR_FD_READ);
660
+
661
+ if (!wfl->displayHandle)
662
+ return FALSE;
663
+
664
+ wfl->events = ArrayList_New(FALSE);
665
+ if (!wfl->events)
666
+ return FALSE;
667
+
668
+ obj = ArrayList_Object(wfl->events);
669
+ obj->fnObjectNew = uwac_event_clone;
670
+ obj->fnObjectFree = free;
671
+
672
+ InitializeCriticalSection(&wfl->critical);
673
+
674
+ return TRUE;
675
+ }
676
+
677
+ static int wfl_client_start(rdpContext* context)
678
+ {
679
+ WINPR_UNUSED(context);
680
+ return 0;
681
+ }
682
+
683
+ static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
684
+ {
685
+ WINPR_ASSERT(pEntryPoints);
686
+ ZeroMemory(pEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS));
687
+ pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION;
688
+ pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
689
+ pEntryPoints->GlobalInit = wlf_client_global_init;
690
+ pEntryPoints->GlobalUninit = wlf_client_global_uninit;
691
+ pEntryPoints->ContextSize = sizeof(wlfContext);
692
+ pEntryPoints->ClientNew = wlf_client_new;
693
+ pEntryPoints->ClientFree = wlf_client_free;
694
+ pEntryPoints->ClientStart = wfl_client_start;
695
+ pEntryPoints->ClientStop = freerdp_client_common_stop;
696
+ return 0;
697
+ }
698
+
699
+ int main(int argc, char* argv[])
700
+ {
701
+ int rc = -1;
702
+ int status = 0;
703
+ RDP_CLIENT_ENTRY_POINTS clientEntryPoints;
704
+ rdpContext* context = NULL;
705
+ rdpSettings* settings = NULL;
706
+ wlfContext* wlc = NULL;
707
+
708
+ freerdp_client_warn_deprecated(argc, argv);
709
+
710
+ RdpClientEntry(&clientEntryPoints);
711
+ context = freerdp_client_context_new(&clientEntryPoints);
712
+ if (!context)
713
+ goto fail;
714
+ wlc = (wlfContext*)context;
715
+ settings = context->settings;
716
+
717
+ status = freerdp_client_settings_parse_command_line(settings, argc, argv, FALSE);
718
+ if (status)
719
+ {
720
+ rc = freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
721
+
722
+ if (freerdp_settings_get_bool(settings, FreeRDP_ListMonitors))
723
+ wlf_list_monitors(wlc);
724
+
725
+ goto fail;
726
+ }
727
+
728
+ if (freerdp_client_start(context) != 0)
729
+ goto fail;
730
+
731
+ rc = wlfreerdp_run(context->instance);
732
+
733
+ if (freerdp_client_stop(context) != 0)
734
+ rc = -1;
735
+
736
+ fail:
737
+ freerdp_client_context_free(context);
738
+ return rc;
739
+ }
740
+
741
+ BOOL wlf_copy_image(const void* src, size_t srcStride, size_t srcWidth, size_t srcHeight, void* dst,
742
+ size_t dstStride, size_t dstWidth, size_t dstHeight, const RECTANGLE_16* area,
743
+ BOOL scale)
744
+ {
745
+ BOOL rc = FALSE;
746
+
747
+ if (!src || !dst || !area)
748
+ return FALSE;
749
+
750
+ if (scale)
751
+ {
752
+ WINPR_ASSERT(dstStride <= UINT32_MAX);
753
+ WINPR_ASSERT(dstWidth <= UINT32_MAX);
754
+ WINPR_ASSERT(dstHeight <= UINT32_MAX);
755
+ WINPR_ASSERT(srcStride <= UINT32_MAX);
756
+ WINPR_ASSERT(srcWidth <= UINT32_MAX);
757
+ WINPR_ASSERT(srcHeight <= UINT32_MAX);
758
+ return freerdp_image_scale(dst, PIXEL_FORMAT_BGRA32, (UINT32)dstStride, 0, 0,
759
+ (UINT32)dstWidth, (UINT32)dstHeight, src, PIXEL_FORMAT_BGRA32,
760
+ (UINT32)srcStride, 0, 0, (UINT32)srcWidth, (UINT32)srcHeight);
761
+ }
762
+ else
763
+ {
764
+ const size_t baseSrcOffset = 1ULL * area->top * srcStride + 4ULL * area->left;
765
+ const size_t baseDstOffset = 1ULL * area->top * dstStride + 4ULL * area->left;
766
+ const size_t width = MIN((size_t)area->right - area->left, dstWidth - area->left);
767
+ const size_t height = MIN((size_t)area->bottom - area->top, dstHeight - area->top);
768
+ const BYTE* psrc = (const BYTE*)src;
769
+ BYTE* pdst = (BYTE*)dst;
770
+
771
+ for (size_t i = 0; i < height; i++)
772
+ {
773
+ const size_t srcOffset = i * srcStride + baseSrcOffset;
774
+ const size_t dstOffset = i * dstStride + baseDstOffset;
775
+ memcpy(&pdst[dstOffset], &psrc[srcOffset], width * 4);
776
+ }
777
+
778
+ rc = TRUE;
779
+ }
780
+
781
+ return rc;
782
+ }
783
+
784
+ BOOL wlf_scale_coordinates(rdpContext* context, UINT32* px, UINT32* py, BOOL fromLocalToRDP)
785
+ {
786
+ wlfContext* wlf = (wlfContext*)context;
787
+ UwacSize geometry = { 0 };
788
+
789
+ if (!context || !px || !py || !context->gdi)
790
+ return FALSE;
791
+
792
+ if (!freerdp_settings_get_bool(context->settings, FreeRDP_SmartSizing))
793
+ return TRUE;
794
+
795
+ rdpGdi* gdi = context->gdi;
796
+
797
+ if (UwacWindowGetDrawingBufferGeometry(wlf->window, &geometry, NULL) != UWAC_SUCCESS)
798
+ return FALSE;
799
+
800
+ const double sx = 1.0 * geometry.width / (double)gdi->width;
801
+ const double sy = 1.0 * geometry.height / (double)gdi->height;
802
+
803
+ if (!fromLocalToRDP)
804
+ {
805
+ *px *= (UINT32)lround(sx);
806
+ *py *= (UINT32)lround(sy);
807
+ }
808
+ else
809
+ {
810
+ *px /= (UINT32)lround(sx);
811
+ *py /= (UINT32)lround(sy);
812
+ }
813
+
814
+ return TRUE;
815
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Wayland/wlfreerdp.h ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Wayland Client
4
+ *
5
+ * Copyright 2014 Manuel Bachmann <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_CLIENT_WAYLAND_FREERDP_H
21
+ #define FREERDP_CLIENT_WAYLAND_FREERDP_H
22
+
23
+ #include <freerdp/client/rdpei.h>
24
+ #include <freerdp/gdi/gfx.h>
25
+ #include <freerdp/freerdp.h>
26
+ #include <freerdp/log.h>
27
+ #include <freerdp/locale/keyboard.h>
28
+ #include <winpr/wtypes.h>
29
+ #include <uwac/uwac.h>
30
+
31
+ typedef struct wlf_clipboard wfClipboard;
32
+ typedef struct s_wlfDispContext wlfDispContext;
33
+
34
+ typedef struct
35
+ {
36
+ rdpClientContext common;
37
+
38
+ UwacDisplay* display;
39
+ HANDLE displayHandle;
40
+ UwacWindow* window;
41
+ UwacSeat* seat;
42
+
43
+ BOOL fullscreen;
44
+ BOOL closed;
45
+ BOOL focusing;
46
+
47
+ /* Channels */
48
+ wfClipboard* clipboard;
49
+ wlfDispContext* disp;
50
+ wLog* log;
51
+ CRITICAL_SECTION critical;
52
+ wArrayList* events;
53
+ FREERDP_REMAP_TABLE* remap_table;
54
+ } wlfContext;
55
+
56
+ BOOL wlf_scale_coordinates(rdpContext* context, UINT32* px, UINT32* py, BOOL fromLocalToRDP);
57
+ BOOL wlf_copy_image(const void* src, size_t srcStride, size_t srcWidth, size_t srcHeight, void* dst,
58
+ size_t dstStride, size_t dstWidth, size_t dstHeight, const RECTANGLE_16* area,
59
+ BOOL scale);
60
+
61
+ #endif /* FREERDP_CLIENT_WAYLAND_FREERDP_H */
local-test-freerdp-delta-01/afc-freerdp/client/Windows/ModuleOptions.cmake ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ set(FREERDP_CLIENT_NAME "wfreerdp")
2
+ set(FREERDP_CLIENT_PLATFORM "Windows")
3
+ set(FREERDP_CLIENT_VENDOR "FreeRDP")
local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_channels.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ *
4
+ * Copyright 2014 Marc-Andre Moreau <[email protected]>
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #ifndef FREERDP_CLIENT_WIN_CHANNELS_H
20
+ #define FREERDP_CLIENT_WIN_CHANNELS_H
21
+
22
+ #include <freerdp/freerdp.h>
23
+ #include <freerdp/client.h>
24
+ #include <freerdp/client/channels.h>
25
+ #include <freerdp/client/rdpei.h>
26
+ #include <freerdp/client/rdpgfx.h>
27
+ #include <freerdp/client/encomsp.h>
28
+ #include <freerdp/client/cliprdr.h>
29
+ #include <freerdp/client/disp.h>
30
+
31
+ #include "wf_client.h"
32
+
33
+ void wf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e);
34
+ void wf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e);
35
+
36
+ #endif /* FREERDP_CLIENT_WIN_CHANNELS_H */
local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_client.c ADDED
@@ -0,0 +1,1490 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Windows Client
4
+ *
5
+ * Copyright 2009-2011 Jay Sorg
6
+ * Copyright 2010-2011 Vic Lee
7
+ * Copyright 2010-2011 Marc-Andre Moreau <[email protected]>
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+
22
+ #include <freerdp/config.h>
23
+
24
+ #include <winpr/windows.h>
25
+ #include <winpr/library.h>
26
+
27
+ #include <winpr/crt.h>
28
+ #include <winpr/assert.h>
29
+
30
+ #include <errno.h>
31
+ #include <stdio.h>
32
+ #include <stdlib.h>
33
+ #include <string.h>
34
+ #include <tchar.h>
35
+ #include <winpr/assert.h>
36
+ #include <sys/types.h>
37
+ #include <io.h>
38
+
39
+ #ifdef WITH_PROGRESS_BAR
40
+ #include <shobjidl.h>
41
+ #endif
42
+
43
+ #ifdef WITH_WINDOWS_CERT_STORE
44
+ #include <wincrypt.h>
45
+ #endif
46
+
47
+ #include <freerdp/log.h>
48
+ #include <freerdp/freerdp.h>
49
+ #include <freerdp/constants.h>
50
+ #include <freerdp/settings.h>
51
+
52
+ #include <freerdp/locale/keyboard.h>
53
+ #include <freerdp/codec/region.h>
54
+ #include <freerdp/client/cmdline.h>
55
+ #include <freerdp/client/channels.h>
56
+ #include <freerdp/channels/channels.h>
57
+
58
+ #include "wf_gdi.h"
59
+ #include "wf_rail.h"
60
+ #include "wf_channels.h"
61
+ #include "wf_graphics.h"
62
+
63
+ #include "resource/resource.h"
64
+
65
+ #define TAG CLIENT_TAG("windows")
66
+
67
+ #define WM_FREERDP_SHOWWINDOW (WM_USER + 100)
68
+
69
+ static BOOL wf_has_console(void)
70
+ {
71
+ #ifdef WITH_WIN_CONSOLE
72
+ int file = _fileno(stdin);
73
+ int tty = _isatty(file);
74
+ #else
75
+ int file = -1;
76
+ int tty = 0;
77
+ #endif
78
+
79
+ WLog_INFO(TAG, "Detected stdin=%d -> %s mode", file, tty ? "console" : "gui");
80
+ return tty;
81
+ }
82
+
83
+ static BOOL wf_end_paint(rdpContext* context)
84
+ {
85
+ rdpGdi* gdi;
86
+ int ninvalid;
87
+ RECT updateRect;
88
+ HGDI_RGN cinvalid;
89
+ REGION16 invalidRegion;
90
+ RECTANGLE_16 invalidRect;
91
+ const RECTANGLE_16* extents;
92
+ wfContext* wfc = (wfContext*)context;
93
+ gdi = context->gdi;
94
+ ninvalid = gdi->primary->hdc->hwnd->ninvalid;
95
+ cinvalid = gdi->primary->hdc->hwnd->cinvalid;
96
+
97
+ if (ninvalid < 1)
98
+ return TRUE;
99
+
100
+ region16_init(&invalidRegion);
101
+
102
+ for (int i = 0; i < ninvalid; i++)
103
+ {
104
+ invalidRect.left = cinvalid[i].x;
105
+ invalidRect.top = cinvalid[i].y;
106
+ invalidRect.right = cinvalid[i].x + cinvalid[i].w;
107
+ invalidRect.bottom = cinvalid[i].y + cinvalid[i].h;
108
+ region16_union_rect(&invalidRegion, &invalidRegion, &invalidRect);
109
+ }
110
+
111
+ if (!region16_is_empty(&invalidRegion))
112
+ {
113
+ extents = region16_extents(&invalidRegion);
114
+ updateRect.left = extents->left;
115
+ updateRect.top = extents->top;
116
+ updateRect.right = extents->right;
117
+ updateRect.bottom = extents->bottom;
118
+
119
+ wf_scale_rect(wfc, &updateRect);
120
+
121
+ InvalidateRect(wfc->hwnd, &updateRect, FALSE);
122
+
123
+ if (wfc->rail)
124
+ wf_rail_invalidate_region(wfc, &invalidRegion);
125
+ }
126
+
127
+ region16_uninit(&invalidRegion);
128
+
129
+ if (!wfc->is_shown)
130
+ {
131
+ wfc->is_shown = TRUE;
132
+
133
+ #ifdef WITH_PROGRESS_BAR
134
+ if (wfc->taskBarList)
135
+ {
136
+ wfc->taskBarList->lpVtbl->SetProgressState(wfc->taskBarList, wfc->hwnd,
137
+ TBPF_NOPROGRESS);
138
+ }
139
+ #endif
140
+
141
+ PostMessage(wfc->hwnd, WM_FREERDP_SHOWWINDOW, 0, 0);
142
+ WLog_INFO(TAG, "Window is shown!");
143
+ }
144
+ return TRUE;
145
+ }
146
+
147
+ static BOOL wf_begin_paint(rdpContext* context)
148
+ {
149
+ HGDI_DC hdc;
150
+
151
+ if (!context || !context->gdi || !context->gdi->primary || !context->gdi->primary->hdc)
152
+ return FALSE;
153
+
154
+ hdc = context->gdi->primary->hdc;
155
+
156
+ if (!hdc || !hdc->hwnd || !hdc->hwnd->invalid)
157
+ return FALSE;
158
+
159
+ hdc->hwnd->invalid->null = TRUE;
160
+ hdc->hwnd->ninvalid = 0;
161
+ return TRUE;
162
+ }
163
+
164
+ static BOOL wf_desktop_resize(rdpContext* context)
165
+ {
166
+ BOOL same;
167
+ RECT rect;
168
+ rdpSettings* settings;
169
+ wfContext* wfc = (wfContext*)context;
170
+
171
+ if (!context || !context->settings)
172
+ return FALSE;
173
+
174
+ settings = context->settings;
175
+
176
+ if (wfc->primary)
177
+ {
178
+ same = (wfc->primary == wfc->drawing) ? TRUE : FALSE;
179
+ wf_image_free(wfc->primary);
180
+ wfc->primary =
181
+ wf_image_new(wfc, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
182
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight),
183
+ context->gdi->dstFormat, NULL);
184
+ }
185
+
186
+ if (!gdi_resize_ex(context->gdi, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
187
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight), 0,
188
+ context->gdi->dstFormat, wfc->primary->pdata, NULL))
189
+ return FALSE;
190
+
191
+ if (same)
192
+ wfc->drawing = wfc->primary;
193
+
194
+ if (wfc->fullscreen != TRUE)
195
+ {
196
+ if (wfc->hwnd && !freerdp_settings_get_bool(settings, FreeRDP_SmartSizing))
197
+ SetWindowPos(wfc->hwnd, HWND_TOP, -1, -1,
198
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) + wfc->diff.x,
199
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) + wfc->diff.y,
200
+ SWP_NOMOVE);
201
+ }
202
+ else
203
+ {
204
+ wf_update_offset(wfc);
205
+ GetWindowRect(wfc->hwnd, &rect);
206
+ InvalidateRect(wfc->hwnd, &rect, TRUE);
207
+ }
208
+
209
+ return TRUE;
210
+ }
211
+
212
+ static BOOL wf_pre_connect(freerdp* instance)
213
+ {
214
+ UINT32 rc;
215
+ wfContext* wfc;
216
+ UINT32 desktopWidth;
217
+ UINT32 desktopHeight;
218
+ rdpContext* context;
219
+ rdpSettings* settings;
220
+
221
+ WINPR_ASSERT(instance);
222
+ WINPR_ASSERT(instance->context);
223
+ WINPR_ASSERT(instance->context->settings);
224
+
225
+ context = instance->context;
226
+ wfc = (wfContext*)instance->context;
227
+ settings = context->settings;
228
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMajorType, OSMAJORTYPE_WINDOWS))
229
+ return FALSE;
230
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_WINDOWS_NT))
231
+ return FALSE;
232
+ wfc->fullscreen = freerdp_settings_get_bool(settings, FreeRDP_Fullscreen);
233
+ wfc->fullscreen_toggle = freerdp_settings_get_bool(settings, FreeRDP_ToggleFullscreen);
234
+ desktopWidth = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
235
+ desktopHeight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
236
+
237
+ if (wfc->percentscreen > 0)
238
+ {
239
+ desktopWidth = (GetSystemMetrics(SM_CXSCREEN) * wfc->percentscreen) / 100;
240
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, desktopWidth))
241
+ return FALSE;
242
+ desktopHeight = (GetSystemMetrics(SM_CYSCREEN) * wfc->percentscreen) / 100;
243
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, desktopHeight))
244
+ return FALSE;
245
+ }
246
+
247
+ if (wfc->fullscreen)
248
+ {
249
+ if (freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
250
+ {
251
+ desktopWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
252
+ desktopHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
253
+ }
254
+ else
255
+ {
256
+ desktopWidth = GetSystemMetrics(SM_CXSCREEN);
257
+ desktopHeight = GetSystemMetrics(SM_CYSCREEN);
258
+ }
259
+ }
260
+
261
+ /* FIXME: desktopWidth has a limitation that it should be divisible by 4,
262
+ * otherwise the screen will crash when connecting to an XP desktop.*/
263
+ desktopWidth = (desktopWidth + 3) & (~3);
264
+
265
+ if (desktopWidth != freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth))
266
+ {
267
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, desktopWidth))
268
+ return FALSE;
269
+ }
270
+
271
+ if (desktopHeight != freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight))
272
+ {
273
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, desktopHeight))
274
+ return FALSE;
275
+ }
276
+
277
+ rc = freerdp_keyboard_init(freerdp_settings_get_uint32(settings, FreeRDP_KeyboardLayout));
278
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_KeyboardLayout, rc))
279
+ return FALSE;
280
+ PubSub_SubscribeChannelConnected(instance->context->pubSub, wf_OnChannelConnectedEventHandler);
281
+ PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
282
+ wf_OnChannelDisconnectedEventHandler);
283
+ return TRUE;
284
+ }
285
+
286
+ static void wf_append_item_to_system_menu(HMENU hMenu, UINT fMask, UINT wID, const wchar_t* text,
287
+ wfContext* wfc)
288
+ {
289
+ MENUITEMINFO item_info = { 0 };
290
+ item_info.fMask = fMask;
291
+ item_info.cbSize = sizeof(MENUITEMINFO);
292
+ item_info.wID = wID;
293
+ item_info.fType = MFT_STRING;
294
+ item_info.dwTypeData = _wcsdup(text);
295
+ item_info.cch = (UINT)_wcslen(text);
296
+ if (wfc)
297
+ item_info.dwItemData = (ULONG_PTR)wfc;
298
+ InsertMenuItem(hMenu, wfc->systemMenuInsertPosition++, TRUE, &item_info);
299
+ }
300
+
301
+ static void wf_add_system_menu(wfContext* wfc)
302
+ {
303
+ HMENU hMenu;
304
+
305
+ if (wfc->fullscreen && !wfc->fullscreen_toggle)
306
+ {
307
+ return;
308
+ }
309
+
310
+ if (freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_DynamicResolutionUpdate))
311
+ {
312
+ return;
313
+ }
314
+
315
+ hMenu = GetSystemMenu(wfc->hwnd, FALSE);
316
+
317
+ wf_append_item_to_system_menu(hMenu,
318
+ MIIM_CHECKMARKS | MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_DATA,
319
+ SYSCOMMAND_ID_SMARTSIZING, L"Smart sizing", wfc);
320
+
321
+ if (freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_SmartSizing))
322
+ {
323
+ CheckMenuItem(hMenu, SYSCOMMAND_ID_SMARTSIZING, MF_CHECKED);
324
+ }
325
+
326
+ if (freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_RemoteAssistanceMode))
327
+ wf_append_item_to_system_menu(hMenu, MIIM_FTYPE | MIIM_ID | MIIM_STRING,
328
+ SYSCOMMAND_ID_REQUEST_CONTROL, L"Request control", wfc);
329
+ }
330
+
331
+ static WCHAR* wf_window_get_title(rdpSettings* settings)
332
+ {
333
+ BOOL port;
334
+ WCHAR* windowTitle = NULL;
335
+ size_t size;
336
+ WCHAR prefix[] = L"FreeRDP:";
337
+
338
+ if (!settings)
339
+ return NULL;
340
+
341
+ const char* name = freerdp_settings_get_string(settings, FreeRDP_ServerHostname);
342
+
343
+ if (freerdp_settings_get_string(settings, FreeRDP_WindowTitle))
344
+ return ConvertUtf8ToWCharAlloc(freerdp_settings_get_string(settings, FreeRDP_WindowTitle),
345
+ NULL);
346
+
347
+ port = (freerdp_settings_get_uint32(settings, FreeRDP_ServerPort) != 3389);
348
+ size = strlen(name) + 16 + wcslen(prefix);
349
+ windowTitle = calloc(size, sizeof(WCHAR));
350
+
351
+ if (!windowTitle)
352
+ return NULL;
353
+
354
+ if (!port)
355
+ _snwprintf_s(windowTitle, size, _TRUNCATE, L"%s %S", prefix, name);
356
+ else
357
+ _snwprintf_s(windowTitle, size, _TRUNCATE, L"%s %S:%u", prefix, name,
358
+ freerdp_settings_get_uint32(settings, FreeRDP_ServerPort));
359
+
360
+ return windowTitle;
361
+ }
362
+
363
+ static BOOL wf_post_connect(freerdp* instance)
364
+ {
365
+ rdpGdi* gdi;
366
+ DWORD dwStyle;
367
+ rdpCache* cache;
368
+ wfContext* wfc;
369
+ rdpContext* context;
370
+ rdpSettings* settings;
371
+ EmbedWindowEventArgs e;
372
+ const UINT32 format = PIXEL_FORMAT_BGRX32;
373
+
374
+ WINPR_ASSERT(instance);
375
+
376
+ context = instance->context;
377
+ WINPR_ASSERT(context);
378
+
379
+ settings = context->settings;
380
+ WINPR_ASSERT(settings);
381
+
382
+ wfc = (wfContext*)instance->context;
383
+ WINPR_ASSERT(wfc);
384
+
385
+ wfc->primary =
386
+ wf_image_new(wfc, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
387
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight), format, NULL);
388
+
389
+ if (!gdi_init_ex(instance, format, 0, wfc->primary->pdata, NULL))
390
+ return FALSE;
391
+
392
+ cache = instance->context->cache;
393
+ WINPR_ASSERT(cache);
394
+
395
+ gdi = instance->context->gdi;
396
+
397
+ if (!freerdp_settings_get_bool(settings, FreeRDP_SoftwareGdi))
398
+ {
399
+ wf_gdi_register_update_callbacks(context->update);
400
+ }
401
+
402
+ wfc->window_title = wf_window_get_title(settings);
403
+
404
+ if (!wfc->window_title)
405
+ return FALSE;
406
+
407
+ if (freerdp_settings_get_bool(settings, FreeRDP_EmbeddedWindow))
408
+ {
409
+ if (!freerdp_settings_set_bool(settings, FreeRDP_Decorations, FALSE))
410
+ return FALSE;
411
+ }
412
+
413
+ if (wfc->fullscreen)
414
+ dwStyle = WS_POPUP;
415
+ else if (!freerdp_settings_get_bool(settings, FreeRDP_Decorations))
416
+ dwStyle = WS_CHILD | WS_BORDER;
417
+ else
418
+ dwStyle =
419
+ WS_CAPTION | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_SIZEBOX | WS_MAXIMIZEBOX;
420
+
421
+ if (!wfc->hwnd)
422
+ {
423
+ wfc->hwnd = CreateWindowEx(0, wfc->wndClassName, wfc->window_title, dwStyle, 0, 0, 0, 0,
424
+ wfc->hWndParent, NULL, wfc->hInstance, NULL);
425
+ SetWindowLongPtr(wfc->hwnd, GWLP_USERDATA, (LONG_PTR)wfc);
426
+ }
427
+
428
+ wf_resize_window(wfc);
429
+ wf_add_system_menu(wfc);
430
+ BitBlt(wfc->primary->hdc, 0, 0, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
431
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight), NULL, 0, 0, BLACKNESS);
432
+ wfc->drawing = wfc->primary;
433
+ EventArgsInit(&e, "wfreerdp");
434
+ e.embed = FALSE;
435
+ e.handle = (void*)wfc->hwnd;
436
+ PubSub_OnEmbedWindow(context->pubSub, context, &e);
437
+ #ifdef WITH_PROGRESS_BAR
438
+ if (wfc->taskBarList)
439
+ {
440
+ ShowWindow(wfc->hwnd, SW_SHOWMINIMIZED);
441
+ wfc->taskBarList->lpVtbl->SetProgressState(wfc->taskBarList, wfc->hwnd, TBPF_INDETERMINATE);
442
+ }
443
+ #endif
444
+ UpdateWindow(wfc->hwnd);
445
+ context->update->BeginPaint = wf_begin_paint;
446
+ context->update->DesktopResize = wf_desktop_resize;
447
+ context->update->EndPaint = wf_end_paint;
448
+ wf_register_pointer(context->graphics);
449
+
450
+ wfc->floatbar = wf_floatbar_new(wfc, wfc->hInstance,
451
+ freerdp_settings_get_uint32(settings, FreeRDP_Floatbar));
452
+ return TRUE;
453
+ }
454
+
455
+ static void wf_post_disconnect(freerdp* instance)
456
+ {
457
+ wfContext* wfc;
458
+
459
+ if (!instance || !instance->context)
460
+ return;
461
+
462
+ wfc = (wfContext*)instance->context;
463
+ free(wfc->window_title);
464
+ }
465
+
466
+ static CREDUI_INFOW wfUiInfo = { sizeof(CREDUI_INFOW), NULL, L"Enter your credentials",
467
+ L"Remote Desktop Security", NULL };
468
+
469
+ static BOOL wf_authenticate_ex(freerdp* instance, char** username, char** password, char** domain,
470
+ rdp_auth_reason reason)
471
+ {
472
+ wfContext* wfc;
473
+ BOOL fSave;
474
+ DWORD status;
475
+ DWORD dwFlags;
476
+ WCHAR UserNameW[CREDUI_MAX_USERNAME_LENGTH + 1] = { 0 };
477
+ WCHAR UserW[CREDUI_MAX_USERNAME_LENGTH + 1] = { 0 };
478
+ WCHAR DomainW[CREDUI_MAX_DOMAIN_TARGET_LENGTH + 1] = { 0 };
479
+ WCHAR PasswordW[CREDUI_MAX_PASSWORD_LENGTH + 1] = { 0 };
480
+
481
+ WINPR_ASSERT(instance);
482
+ WINPR_ASSERT(instance->context);
483
+ WINPR_ASSERT(instance->context->settings);
484
+
485
+ wfc = (wfContext*)instance->context;
486
+ WINPR_ASSERT(wfc);
487
+
488
+ WINPR_ASSERT(username);
489
+ WINPR_ASSERT(domain);
490
+ WINPR_ASSERT(password);
491
+
492
+ const WCHAR auth[] = L"Target credentials requested";
493
+ const WCHAR authPin[] = L"PIN requested";
494
+ const WCHAR gwAuth[] = L"Gateway credentials requested";
495
+ const WCHAR* titleW = auth;
496
+
497
+ fSave = FALSE;
498
+ dwFlags = CREDUI_FLAGS_DO_NOT_PERSIST | CREDUI_FLAGS_EXCLUDE_CERTIFICATES |
499
+ CREDUI_FLAGS_USERNAME_TARGET_CREDENTIALS;
500
+ switch (reason)
501
+ {
502
+ case AUTH_NLA:
503
+ break;
504
+ case AUTH_TLS:
505
+ case AUTH_RDP:
506
+ if ((*username) && (*password))
507
+ return TRUE;
508
+ break;
509
+ case AUTH_SMARTCARD_PIN:
510
+ dwFlags &= ~CREDUI_FLAGS_USERNAME_TARGET_CREDENTIALS;
511
+ dwFlags |= CREDUI_FLAGS_PASSWORD_ONLY_OK | CREDUI_FLAGS_KEEP_USERNAME;
512
+ titleW = authPin;
513
+ if (*password)
514
+ return TRUE;
515
+ if (!(*username))
516
+ *username = _strdup("PIN");
517
+ break;
518
+ case GW_AUTH_HTTP:
519
+ case GW_AUTH_RDG:
520
+ case GW_AUTH_RPC:
521
+ titleW = gwAuth;
522
+ break;
523
+ default:
524
+ return FALSE;
525
+ }
526
+
527
+ if (*username)
528
+ {
529
+ (void)ConvertUtf8ToWChar(*username, UserNameW, ARRAYSIZE(UserNameW));
530
+ (void)ConvertUtf8ToWChar(*username, UserW, ARRAYSIZE(UserW));
531
+ }
532
+
533
+ if (*password)
534
+ (void)ConvertUtf8ToWChar(*password, PasswordW, ARRAYSIZE(PasswordW));
535
+
536
+ if (*domain)
537
+ (void)ConvertUtf8ToWChar(*domain, DomainW, ARRAYSIZE(DomainW));
538
+
539
+ if (_wcsnlen(PasswordW, ARRAYSIZE(PasswordW)) == 0)
540
+ {
541
+ if (!wfc->isConsole &&
542
+ freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_CredentialsFromStdin))
543
+ WLog_ERR(TAG, "Flag for stdin read present but stdin is redirected; using GUI");
544
+ if (wfc->isConsole &&
545
+ freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_CredentialsFromStdin))
546
+ status = CredUICmdLinePromptForCredentialsW(titleW, NULL, 0, UserNameW,
547
+ ARRAYSIZE(UserNameW), PasswordW,
548
+ ARRAYSIZE(PasswordW), &fSave, dwFlags);
549
+ else
550
+ status = CredUIPromptForCredentialsW(&wfUiInfo, titleW, NULL, 0, UserNameW,
551
+ ARRAYSIZE(UserNameW), PasswordW,
552
+ ARRAYSIZE(PasswordW), &fSave, dwFlags);
553
+ if (status != NO_ERROR)
554
+ {
555
+ WLog_ERR(TAG, "CredUIPromptForCredentials unexpected status: 0x%08lX", status);
556
+ return FALSE;
557
+ }
558
+
559
+ if ((dwFlags & CREDUI_FLAGS_KEEP_USERNAME) == 0)
560
+ {
561
+ status = CredUIParseUserNameW(UserNameW, UserW, ARRAYSIZE(UserW), DomainW,
562
+ ARRAYSIZE(DomainW));
563
+ if (status != NO_ERROR)
564
+ {
565
+ CHAR User[CREDUI_MAX_USERNAME_LENGTH + 1] = { 0 };
566
+ CHAR UserName[CREDUI_MAX_USERNAME_LENGTH + 1] = { 0 };
567
+ CHAR Domain[CREDUI_MAX_DOMAIN_TARGET_LENGTH + 1] = { 0 };
568
+
569
+ (void)ConvertWCharNToUtf8(UserNameW, ARRAYSIZE(UserNameW), UserName,
570
+ ARRAYSIZE(UserName));
571
+ (void)ConvertWCharNToUtf8(UserW, ARRAYSIZE(UserW), User, ARRAYSIZE(User));
572
+ (void)ConvertWCharNToUtf8(DomainW, ARRAYSIZE(DomainW), Domain, ARRAYSIZE(Domain));
573
+ WLog_ERR(TAG, "Failed to parse UserName: %s into User: %s Domain: %s", UserName,
574
+ User, Domain);
575
+ return FALSE;
576
+ }
577
+ }
578
+ }
579
+
580
+ *username = ConvertWCharNToUtf8Alloc(UserW, ARRAYSIZE(UserW), NULL);
581
+ if (!(*username))
582
+ {
583
+ WLog_ERR(TAG, "ConvertWCharNToUtf8Alloc failed", status);
584
+ return FALSE;
585
+ }
586
+
587
+ if (_wcsnlen(DomainW, ARRAYSIZE(DomainW)) > 0)
588
+ *domain = ConvertWCharNToUtf8Alloc(DomainW, ARRAYSIZE(DomainW), NULL);
589
+ else
590
+ *domain = _strdup("\0");
591
+
592
+ if (!(*domain))
593
+ {
594
+ free(*username);
595
+ WLog_ERR(TAG, "strdup failed", status);
596
+ return FALSE;
597
+ }
598
+
599
+ *password = ConvertWCharNToUtf8Alloc(PasswordW, ARRAYSIZE(PasswordW), NULL);
600
+ if (!(*password))
601
+ {
602
+ free(*username);
603
+ free(*domain);
604
+ return FALSE;
605
+ }
606
+
607
+ return TRUE;
608
+ }
609
+
610
+ static WCHAR* wf_format_text(const WCHAR* fmt, ...)
611
+ {
612
+ int rc;
613
+ size_t size = 0;
614
+ WCHAR* buffer = NULL;
615
+
616
+ do
617
+ {
618
+ WCHAR* tmp;
619
+ va_list ap;
620
+ va_start(ap, fmt);
621
+ rc = _vsnwprintf(buffer, size, fmt, ap);
622
+ va_end(ap);
623
+ if (rc <= 0)
624
+ goto fail;
625
+
626
+ if ((size_t)rc < size)
627
+ return buffer;
628
+
629
+ size = (size_t)rc + 1;
630
+ tmp = realloc(buffer, size * sizeof(WCHAR));
631
+ if (!tmp)
632
+ goto fail;
633
+
634
+ buffer = tmp;
635
+ } while (TRUE);
636
+
637
+ fail:
638
+ free(buffer);
639
+ return NULL;
640
+ }
641
+
642
+ #ifdef WITH_WINDOWS_CERT_STORE
643
+ /* https://stackoverflow.com/questions/1231178/load-an-pem-encoded-x-509-certificate-into-windows-cryptoapi/3803333#3803333
644
+ */
645
+ /* https://github.com/microsoft/Windows-classic-samples/blob/main/Samples/Win7Samples/security/cryptoapi/peertrust/cpp/peertrust.cpp
646
+ */
647
+ /* https://stackoverflow.com/questions/7340504/whats-the-correct-way-to-verify-an-ssl-certificate-in-win32
648
+ */
649
+
650
+ static void wf_report_error(char* wszMessage, DWORD dwErrCode)
651
+ {
652
+ LPSTR pwszMsgBuf = NULL;
653
+
654
+ if (NULL != wszMessage && 0 != *wszMessage)
655
+ {
656
+ WLog_ERR(TAG, "%s", wszMessage);
657
+ }
658
+
659
+ FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
660
+ NULL, // Location of message
661
+ // definition ignored
662
+ dwErrCode, // Message identifier for
663
+ // the requested message
664
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Language identifier for
665
+ // the requested message
666
+ (LPSTR)&pwszMsgBuf, // Buffer that receives
667
+ // the formatted message
668
+ 0, // Size of output buffer
669
+ // not needed as allocate
670
+ // buffer flag is set
671
+ NULL // Array of insert values
672
+ );
673
+
674
+ if (NULL != pwszMsgBuf)
675
+ {
676
+ WLog_ERR(TAG, "Error: 0x%08x (%d) %s", dwErrCode, dwErrCode, pwszMsgBuf);
677
+ LocalFree(pwszMsgBuf);
678
+ }
679
+ else
680
+ {
681
+ WLog_ERR(TAG, "Error: 0x%08x (%d)", dwErrCode, dwErrCode);
682
+ }
683
+ }
684
+
685
+ static DWORD wf_is_x509_certificate_trusted(const char* common_name, const char* subject,
686
+ const char* issuer, const char* fingerprint)
687
+ {
688
+ HRESULT hr = CRYPT_E_NOT_FOUND;
689
+
690
+ DWORD dwChainFlags = CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT;
691
+ PCCERT_CONTEXT pCert = NULL;
692
+ HCERTCHAINENGINE hChainEngine = NULL;
693
+ PCCERT_CHAIN_CONTEXT pChainContext = NULL;
694
+
695
+ CERT_ENHKEY_USAGE EnhkeyUsage = { 0 };
696
+ CERT_USAGE_MATCH CertUsage = { 0 };
697
+ CERT_CHAIN_PARA ChainPara = { 0 };
698
+ CERT_CHAIN_POLICY_PARA ChainPolicy = { 0 };
699
+ CERT_CHAIN_POLICY_STATUS PolicyStatus = { 0 };
700
+ CERT_CHAIN_ENGINE_CONFIG EngineConfig = { 0 };
701
+
702
+ DWORD derPubKeyLen = strlen(fingerprint);
703
+ char* derPubKey = calloc(derPubKeyLen, sizeof(char));
704
+ if (NULL == derPubKey)
705
+ {
706
+ WLog_ERR(TAG, "Could not allocate derPubKey");
707
+ goto CleanUp;
708
+ }
709
+
710
+ /*
711
+ * Convert from PEM format to DER format - removes header and footer and decodes from base64
712
+ */
713
+ if (!CryptStringToBinaryA(fingerprint, 0, CRYPT_STRING_BASE64HEADER, derPubKey, &derPubKeyLen,
714
+ NULL, NULL))
715
+ {
716
+ WLog_ERR(TAG, "CryptStringToBinary failed. Err: %d", GetLastError());
717
+ goto CleanUp;
718
+ }
719
+
720
+ //---------------------------------------------------------
721
+ // Initialize data structures for chain building.
722
+
723
+ EnhkeyUsage.cUsageIdentifier = 0;
724
+ EnhkeyUsage.rgpszUsageIdentifier = NULL;
725
+
726
+ CertUsage.dwType = USAGE_MATCH_TYPE_AND;
727
+ CertUsage.Usage = EnhkeyUsage;
728
+
729
+ ChainPara.cbSize = sizeof(ChainPara);
730
+ ChainPara.RequestedUsage = CertUsage;
731
+
732
+ ChainPolicy.cbSize = sizeof(ChainPolicy);
733
+
734
+ PolicyStatus.cbSize = sizeof(PolicyStatus);
735
+
736
+ EngineConfig.cbSize = sizeof(EngineConfig);
737
+ EngineConfig.dwUrlRetrievalTimeout = 0;
738
+
739
+ pCert = CertCreateCertificateContext(X509_ASN_ENCODING, derPubKey, derPubKeyLen);
740
+ if (NULL == pCert)
741
+ {
742
+ WLog_ERR(TAG, "FAILED: Certificate could not be parsed.");
743
+ goto CleanUp;
744
+ }
745
+
746
+ dwChainFlags |= CERT_CHAIN_ENABLE_PEER_TRUST;
747
+
748
+ // When this flag is set, end entity certificates in the
749
+ // Trusted People store are trusted without doing any chain building
750
+ // This optimizes the chain building process.
751
+
752
+ //---------------------------------------------------------
753
+ // Create chain engine.
754
+
755
+ if (!CertCreateCertificateChainEngine(&EngineConfig, &hChainEngine))
756
+ {
757
+ hr = HRESULT_FROM_WIN32(GetLastError());
758
+ goto CleanUp;
759
+ }
760
+
761
+ //-------------------------------------------------------------------
762
+ // Build a chain using CertGetCertificateChain
763
+
764
+ if (!CertGetCertificateChain(hChainEngine, // use the default chain engine
765
+ pCert, // pointer to the end certificate
766
+ NULL, // use the default time
767
+ NULL, // search no additional stores
768
+ &ChainPara, // use AND logic and enhanced key usage
769
+ // as indicated in the ChainPara
770
+ // data structure
771
+ dwChainFlags,
772
+ NULL, // currently reserved
773
+ &pChainContext)) // return a pointer to the chain created
774
+ {
775
+ hr = HRESULT_FROM_WIN32(GetLastError());
776
+ goto CleanUp;
777
+ }
778
+
779
+ //---------------------------------------------------------------
780
+ // Verify that the chain complies with policy
781
+
782
+ if (!CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_BASE, // use the base policy
783
+ pChainContext, // pointer to the chain
784
+ &ChainPolicy,
785
+ &PolicyStatus)) // return a pointer to the policy status
786
+ {
787
+ hr = HRESULT_FROM_WIN32(GetLastError());
788
+ goto CleanUp;
789
+ }
790
+
791
+ if (PolicyStatus.dwError != S_OK)
792
+ {
793
+ wf_report_error("CertVerifyCertificateChainPolicy: Chain Status", PolicyStatus.dwError);
794
+ hr = PolicyStatus.dwError;
795
+ // Instruction: If the PolicyStatus.dwError is CRYPT_E_NO_REVOCATION_CHECK or
796
+ // CRYPT_E_REVOCATION_OFFLINE, it indicates errors in obtaining
797
+ // revocation information. These can be ignored since the retrieval of
798
+ // revocation information depends on network availability
799
+
800
+ if (PolicyStatus.dwError == CRYPT_E_NO_REVOCATION_CHECK ||
801
+ PolicyStatus.dwError == CRYPT_E_REVOCATION_OFFLINE)
802
+ {
803
+ hr = S_OK;
804
+ }
805
+
806
+ goto CleanUp;
807
+ }
808
+
809
+ WLog_INFO(TAG, "CertVerifyCertificateChainPolicy succeeded for %s (%s) issued by %s",
810
+ common_name, subject, issuer);
811
+
812
+ hr = S_OK;
813
+ CleanUp:
814
+
815
+ if (FAILED(hr))
816
+ {
817
+ WLog_INFO(TAG, "CertVerifyCertificateChainPolicy failed for %s (%s) issued by %s",
818
+ common_name, subject, issuer);
819
+ wf_report_error(NULL, hr);
820
+ }
821
+
822
+ free(derPubKey);
823
+
824
+ if (NULL != pChainContext)
825
+ {
826
+ CertFreeCertificateChain(pChainContext);
827
+ }
828
+
829
+ if (NULL != hChainEngine)
830
+ {
831
+ CertFreeCertificateChainEngine(hChainEngine);
832
+ }
833
+
834
+ if (NULL != pCert)
835
+ {
836
+ CertFreeCertificateContext(pCert);
837
+ }
838
+
839
+ return (DWORD)hr;
840
+ }
841
+ #endif
842
+
843
+ static DWORD wf_cli_verify_certificate_ex(freerdp* instance, const char* host, UINT16 port,
844
+ const char* common_name, const char* subject,
845
+ const char* issuer, const char* fingerprint, DWORD flags)
846
+ {
847
+ #ifdef WITH_WINDOWS_CERT_STORE
848
+ if (flags & VERIFY_CERT_FLAG_FP_IS_PEM && !(flags & VERIFY_CERT_FLAG_MISMATCH))
849
+ {
850
+ if (wf_is_x509_certificate_trusted(common_name, subject, issuer, fingerprint) == S_OK)
851
+ {
852
+ return 2;
853
+ }
854
+ }
855
+ #endif
856
+
857
+ return client_cli_verify_certificate_ex(instance, host, port, common_name, subject, issuer,
858
+ fingerprint, flags);
859
+ }
860
+
861
+ static DWORD wf_verify_certificate_ex(freerdp* instance, const char* host, UINT16 port,
862
+ const char* common_name, const char* subject,
863
+ const char* issuer, const char* fingerprint, DWORD flags)
864
+ {
865
+ WCHAR* buffer;
866
+ WCHAR* caption;
867
+ int what = IDCANCEL;
868
+
869
+ #ifdef WITH_WINDOWS_CERT_STORE
870
+ if (flags & VERIFY_CERT_FLAG_FP_IS_PEM && !(flags & VERIFY_CERT_FLAG_MISMATCH))
871
+ {
872
+ if (wf_is_x509_certificate_trusted(common_name, subject, issuer, fingerprint) == S_OK)
873
+ {
874
+ return 2;
875
+ }
876
+ }
877
+ #endif
878
+
879
+ buffer = wf_format_text(
880
+ L"Certificate details:\n"
881
+ L"\tCommonName: %S\n"
882
+ L"\tSubject: %S\n"
883
+ L"\tIssuer: %S\n"
884
+ L"\tThumbprint: %S\n"
885
+ L"\tHostMismatch: %S\n"
886
+ L"\n"
887
+ L"The above X.509 certificate could not be verified, possibly because you do not have "
888
+ L"the CA certificate in your certificate store, or the certificate has expired. "
889
+ L"Please look at the OpenSSL documentation on how to add a private CA to the store.\n"
890
+ L"\n"
891
+ L"YES\tAccept permanently\n"
892
+ L"NO\tAccept for this session only\n"
893
+ L"CANCEL\tAbort connection\n",
894
+ common_name, subject, issuer, fingerprint,
895
+ flags & VERIFY_CERT_FLAG_MISMATCH ? "Yes" : "No");
896
+ caption = wf_format_text(L"Verify certificate for %S:%hu", host, port);
897
+
898
+ WINPR_UNUSED(instance);
899
+
900
+ if (!buffer || !caption)
901
+ goto fail;
902
+
903
+ what = MessageBoxW(NULL, buffer, caption, MB_YESNOCANCEL);
904
+ fail:
905
+ free(buffer);
906
+ free(caption);
907
+
908
+ /* return 1 to accept and store a certificate, 2 to accept
909
+ * a certificate only for this session, 0 otherwise */
910
+ switch (what)
911
+ {
912
+ case IDYES:
913
+ return 1;
914
+ case IDNO:
915
+ return 2;
916
+ default:
917
+ return 0;
918
+ }
919
+ }
920
+
921
+ static DWORD wf_verify_changed_certificate_ex(freerdp* instance, const char* host, UINT16 port,
922
+ const char* common_name, const char* subject,
923
+ const char* issuer, const char* new_fingerprint,
924
+ const char* old_subject, const char* old_issuer,
925
+ const char* old_fingerprint, DWORD flags)
926
+ {
927
+ WCHAR* buffer;
928
+ WCHAR* caption;
929
+ int what = IDCANCEL;
930
+
931
+ buffer = wf_format_text(
932
+ L"New Certificate details:\n"
933
+ L"\tCommonName: %S\n"
934
+ L"\tSubject: %S\n"
935
+ L"\tIssuer: %S\n"
936
+ L"\tThumbprint: %S\n"
937
+ L"\tHostMismatch: %S\n"
938
+ L"\n"
939
+ L"Old Certificate details:\n"
940
+ L"\tSubject: %S\n"
941
+ L"\tIssuer: %S\n"
942
+ L"\tThumbprint: %S"
943
+ L"The above X.509 certificate could not be verified, possibly because you do not have "
944
+ L"the CA certificate in your certificate store, or the certificate has expired. "
945
+ L"Please look at the OpenSSL documentation on how to add a private CA to the store.\n"
946
+ L"\n"
947
+ L"YES\tAccept permanently\n"
948
+ L"NO\tAccept for this session only\n"
949
+ L"CANCEL\tAbort connection\n",
950
+ common_name, subject, issuer, new_fingerprint,
951
+ flags & VERIFY_CERT_FLAG_MISMATCH ? "Yes" : "No", old_subject, old_issuer, old_fingerprint);
952
+ caption = wf_format_text(L"Verify certificate change for %S:%hu", host, port);
953
+
954
+ WINPR_UNUSED(instance);
955
+ if (!buffer || !caption)
956
+ goto fail;
957
+
958
+ what = MessageBoxW(NULL, buffer, caption, MB_YESNOCANCEL);
959
+ fail:
960
+ free(buffer);
961
+ free(caption);
962
+
963
+ /* return 1 to accept and store a certificate, 2 to accept
964
+ * a certificate only for this session, 0 otherwise */
965
+ switch (what)
966
+ {
967
+ case IDYES:
968
+ return 1;
969
+ case IDNO:
970
+ return 2;
971
+ default:
972
+ return 0;
973
+ }
974
+ }
975
+
976
+ static BOOL wf_present_gateway_message(freerdp* instance, UINT32 type, BOOL isDisplayMandatory,
977
+ BOOL isConsentMandatory, size_t length, const WCHAR* message)
978
+ {
979
+ if (!isDisplayMandatory && !isConsentMandatory)
980
+ return TRUE;
981
+
982
+ /* special handling for consent messages (show modal dialog) */
983
+ if (type == GATEWAY_MESSAGE_CONSENT && isConsentMandatory)
984
+ {
985
+ int mbRes;
986
+ WCHAR* msg;
987
+
988
+ msg = wf_format_text(L"%.*s\n\nI understand and agree to the terms of this policy", length,
989
+ message);
990
+ mbRes = MessageBoxW(NULL, msg, L"Consent Message", MB_YESNO);
991
+ free(msg);
992
+
993
+ if (mbRes != IDYES)
994
+ return FALSE;
995
+ }
996
+ else
997
+ return client_cli_present_gateway_message(instance, type, isDisplayMandatory,
998
+ isConsentMandatory, length, message);
999
+
1000
+ return TRUE;
1001
+ }
1002
+
1003
+ static DWORD WINAPI wf_client_thread(LPVOID lpParam)
1004
+ {
1005
+ MSG msg = { 0 };
1006
+ int width = 0;
1007
+ int height = 0;
1008
+ BOOL msg_ret = FALSE;
1009
+ int quit_msg = 0;
1010
+ DWORD error = 0;
1011
+
1012
+ freerdp* instance = (freerdp*)lpParam;
1013
+ WINPR_ASSERT(instance);
1014
+
1015
+ if (!freerdp_connect(instance))
1016
+ goto end;
1017
+
1018
+ rdpContext* context = instance->context;
1019
+ WINPR_ASSERT(context);
1020
+
1021
+ wfContext* wfc = (wfContext*)instance->context;
1022
+ WINPR_ASSERT(wfc);
1023
+
1024
+ rdpChannels* channels = context->channels;
1025
+ WINPR_ASSERT(channels);
1026
+
1027
+ rdpSettings* settings = context->settings;
1028
+ WINPR_ASSERT(settings);
1029
+
1030
+ while (!freerdp_shall_disconnect_context(instance->context))
1031
+ {
1032
+ HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
1033
+ DWORD nCount = 0;
1034
+
1035
+ if (freerdp_focus_required(instance))
1036
+ {
1037
+ wf_event_focus_in(wfc);
1038
+ wf_event_focus_in(wfc);
1039
+ }
1040
+
1041
+ {
1042
+ DWORD tmp = freerdp_get_event_handles(context, &handles[nCount], 64 - nCount);
1043
+
1044
+ if (tmp == 0)
1045
+ {
1046
+ WLog_ERR(TAG, "freerdp_get_event_handles failed");
1047
+ break;
1048
+ }
1049
+
1050
+ nCount += tmp;
1051
+ }
1052
+
1053
+ DWORD status = MsgWaitForMultipleObjectsEx(nCount, handles, 5 * 1000, QS_ALLINPUT,
1054
+ MWMO_ALERTABLE | MWMO_INPUTAVAILABLE);
1055
+ if (status == WAIT_FAILED)
1056
+ {
1057
+ WLog_ERR(TAG, "wfreerdp_run: WaitForMultipleObjects failed: 0x%08lX", GetLastError());
1058
+ break;
1059
+ }
1060
+
1061
+ {
1062
+ if (!freerdp_check_event_handles(context))
1063
+ {
1064
+ if (client_auto_reconnect(instance))
1065
+ continue;
1066
+
1067
+ WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
1068
+ break;
1069
+ }
1070
+ }
1071
+
1072
+ if (freerdp_shall_disconnect_context(instance->context))
1073
+ break;
1074
+
1075
+ quit_msg = FALSE;
1076
+
1077
+ while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
1078
+ {
1079
+ msg_ret = GetMessage(&msg, NULL, 0, 0);
1080
+
1081
+ if (freerdp_settings_get_bool(settings, FreeRDP_EmbeddedWindow))
1082
+ {
1083
+ if ((msg.message == WM_SETFOCUS) && (msg.lParam == 1))
1084
+ {
1085
+ PostMessage(wfc->hwnd, WM_SETFOCUS, 0, 0);
1086
+ }
1087
+ else if ((msg.message == WM_KILLFOCUS) && (msg.lParam == 1))
1088
+ {
1089
+ PostMessage(wfc->hwnd, WM_KILLFOCUS, 0, 0);
1090
+ }
1091
+ }
1092
+
1093
+ switch (msg.message)
1094
+ {
1095
+ case WM_SIZE:
1096
+ {
1097
+ width = LOWORD(msg.lParam);
1098
+ height = HIWORD(msg.lParam);
1099
+ SetWindowPos(wfc->hwnd, HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
1100
+ break;
1101
+ }
1102
+ case WM_FREERDP_SHOWWINDOW:
1103
+ {
1104
+ ShowWindow(wfc->hwnd, SW_NORMAL);
1105
+ break;
1106
+ }
1107
+ default:
1108
+ break;
1109
+ }
1110
+
1111
+ if ((msg_ret == 0) || (msg_ret == -1))
1112
+ {
1113
+ quit_msg = TRUE;
1114
+ break;
1115
+ }
1116
+
1117
+ TranslateMessage(&msg);
1118
+ DispatchMessage(&msg);
1119
+ }
1120
+
1121
+ if (quit_msg)
1122
+ break;
1123
+ }
1124
+
1125
+ /* cleanup */
1126
+ freerdp_disconnect(instance);
1127
+
1128
+ end:
1129
+ error = freerdp_get_last_error(instance->context);
1130
+ WLog_DBG(TAG, "Main thread exited with %" PRIu32, error);
1131
+ ExitThread(error);
1132
+ return error;
1133
+ }
1134
+
1135
+ static DWORD WINAPI wf_keyboard_thread(LPVOID lpParam)
1136
+ {
1137
+ MSG msg;
1138
+ BOOL status;
1139
+ wfContext* wfc;
1140
+ HHOOK hook_handle;
1141
+ wfc = (wfContext*)lpParam;
1142
+ WINPR_ASSERT(NULL != wfc);
1143
+ hook_handle = SetWindowsHookEx(WH_KEYBOARD_LL, wf_ll_kbd_proc, wfc->hInstance, 0);
1144
+
1145
+ if (hook_handle)
1146
+ {
1147
+ while ((status = GetMessage(&msg, NULL, 0, 0)) != 0)
1148
+ {
1149
+ if (status == -1)
1150
+ {
1151
+ WLog_ERR(TAG, "keyboard thread error getting message");
1152
+ break;
1153
+ }
1154
+ else
1155
+ {
1156
+ TranslateMessage(&msg);
1157
+ DispatchMessage(&msg);
1158
+ }
1159
+ }
1160
+
1161
+ UnhookWindowsHookEx(hook_handle);
1162
+ }
1163
+ else
1164
+ {
1165
+ WLog_ERR(TAG, "failed to install keyboard hook");
1166
+ }
1167
+
1168
+ WLog_DBG(TAG, "Keyboard thread exited.");
1169
+ ExitThread(0);
1170
+ return 0;
1171
+ }
1172
+
1173
+ int freerdp_client_set_window_size(wfContext* wfc, int width, int height)
1174
+ {
1175
+ WLog_DBG(TAG, "freerdp_client_set_window_size %d, %d", width, height);
1176
+
1177
+ if ((width != wfc->client_width) || (height != wfc->client_height))
1178
+ {
1179
+ PostThreadMessage(wfc->mainThreadId, WM_SIZE, SIZE_RESTORED,
1180
+ ((UINT)height << 16) | (UINT)width);
1181
+ }
1182
+
1183
+ return 0;
1184
+ }
1185
+
1186
+ void wf_size_scrollbars(wfContext* wfc, UINT32 client_width, UINT32 client_height)
1187
+ {
1188
+ const rdpSettings* settings;
1189
+ WINPR_ASSERT(wfc);
1190
+
1191
+ settings = wfc->common.context.settings;
1192
+ WINPR_ASSERT(settings);
1193
+
1194
+ if (wfc->disablewindowtracking)
1195
+ return;
1196
+
1197
+ // prevent infinite message loop
1198
+ wfc->disablewindowtracking = TRUE;
1199
+
1200
+ if (freerdp_settings_get_bool(settings, FreeRDP_SmartSizing) ||
1201
+ freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate))
1202
+ {
1203
+ wfc->xCurrentScroll = 0;
1204
+ wfc->yCurrentScroll = 0;
1205
+
1206
+ if (wfc->xScrollVisible || wfc->yScrollVisible)
1207
+ {
1208
+ if (ShowScrollBar(wfc->hwnd, SB_BOTH, FALSE))
1209
+ {
1210
+ wfc->xScrollVisible = FALSE;
1211
+ wfc->yScrollVisible = FALSE;
1212
+ }
1213
+ }
1214
+ }
1215
+ else
1216
+ {
1217
+ SCROLLINFO si;
1218
+ BOOL horiz = wfc->xScrollVisible;
1219
+ BOOL vert = wfc->yScrollVisible;
1220
+
1221
+ if (!horiz && client_width < freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth))
1222
+ {
1223
+ horiz = TRUE;
1224
+ }
1225
+ else if (horiz &&
1226
+ client_width >=
1227
+ freerdp_settings_get_uint32(
1228
+ settings, FreeRDP_DesktopWidth) /* - GetSystemMetrics(SM_CXVSCROLL)*/)
1229
+ {
1230
+ horiz = FALSE;
1231
+ }
1232
+
1233
+ if (!vert && client_height < freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight))
1234
+ {
1235
+ vert = TRUE;
1236
+ }
1237
+ else if (vert &&
1238
+ client_height >=
1239
+ freerdp_settings_get_uint32(
1240
+ settings, FreeRDP_DesktopHeight) /* - GetSystemMetrics(SM_CYHSCROLL)*/)
1241
+ {
1242
+ vert = FALSE;
1243
+ }
1244
+
1245
+ if (horiz == vert && (horiz != wfc->xScrollVisible && vert != wfc->yScrollVisible))
1246
+ {
1247
+ if (ShowScrollBar(wfc->hwnd, SB_BOTH, horiz))
1248
+ {
1249
+ wfc->xScrollVisible = horiz;
1250
+ wfc->yScrollVisible = vert;
1251
+ }
1252
+ }
1253
+
1254
+ if (horiz != wfc->xScrollVisible)
1255
+ {
1256
+ if (ShowScrollBar(wfc->hwnd, SB_HORZ, horiz))
1257
+ {
1258
+ wfc->xScrollVisible = horiz;
1259
+ }
1260
+ }
1261
+
1262
+ if (vert != wfc->yScrollVisible)
1263
+ {
1264
+ if (ShowScrollBar(wfc->hwnd, SB_VERT, vert))
1265
+ {
1266
+ wfc->yScrollVisible = vert;
1267
+ }
1268
+ }
1269
+
1270
+ if (horiz)
1271
+ {
1272
+ // The horizontal scrolling range is defined by
1273
+ // (bitmap_width) - (client_width). The current horizontal
1274
+ // scroll value remains within the horizontal scrolling range.
1275
+ wfc->xMaxScroll =
1276
+ MAX(freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) - client_width, 0);
1277
+ wfc->xCurrentScroll = MIN(wfc->xCurrentScroll, wfc->xMaxScroll);
1278
+ si.cbSize = sizeof(si);
1279
+ si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
1280
+ si.nMin = wfc->xMinScroll;
1281
+ si.nMax = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
1282
+ si.nPage = client_width;
1283
+ si.nPos = wfc->xCurrentScroll;
1284
+ SetScrollInfo(wfc->hwnd, SB_HORZ, &si, TRUE);
1285
+ }
1286
+
1287
+ if (vert)
1288
+ {
1289
+ // The vertical scrolling range is defined by
1290
+ // (bitmap_height) - (client_height). The current vertical
1291
+ // scroll value remains within the vertical scrolling range.
1292
+ wfc->yMaxScroll = MAX(
1293
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) - client_height, 0);
1294
+ wfc->yCurrentScroll = MIN(wfc->yCurrentScroll, wfc->yMaxScroll);
1295
+ si.cbSize = sizeof(si);
1296
+ si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
1297
+ si.nMin = wfc->yMinScroll;
1298
+ si.nMax = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
1299
+ si.nPage = client_height;
1300
+ si.nPos = wfc->yCurrentScroll;
1301
+ SetScrollInfo(wfc->hwnd, SB_VERT, &si, TRUE);
1302
+ }
1303
+ }
1304
+
1305
+ wfc->disablewindowtracking = FALSE;
1306
+ wf_update_canvas_diff(wfc);
1307
+ }
1308
+
1309
+ static BOOL wfreerdp_client_global_init(void)
1310
+ {
1311
+ WSADATA wsaData;
1312
+
1313
+ WSAStartup(0x101, &wsaData);
1314
+
1315
+ freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0);
1316
+
1317
+ return TRUE;
1318
+ }
1319
+
1320
+ static void wfreerdp_client_global_uninit(void)
1321
+ {
1322
+ WSACleanup();
1323
+ }
1324
+
1325
+ static BOOL wfreerdp_client_new(freerdp* instance, rdpContext* context)
1326
+ {
1327
+ wfContext* wfc = (wfContext*)context;
1328
+ if (!wfc)
1329
+ return FALSE;
1330
+
1331
+ // AttachConsole and stdin do not work well.
1332
+ // Use GUI input dialogs instead of command line ones.
1333
+ wfc->isConsole = wf_has_console();
1334
+
1335
+ if (!(wfreerdp_client_global_init()))
1336
+ return FALSE;
1337
+
1338
+ WINPR_ASSERT(instance);
1339
+ instance->PreConnect = wf_pre_connect;
1340
+ instance->PostConnect = wf_post_connect;
1341
+ instance->PostDisconnect = wf_post_disconnect;
1342
+ instance->AuthenticateEx = wf_authenticate_ex;
1343
+
1344
+ #ifdef WITH_WINDOWS_CERT_STORE
1345
+ if (!freerdp_settings_set_bool(context->settings, FreeRDP_CertificateCallbackPreferPEM, TRUE))
1346
+ return FALSE;
1347
+ #endif
1348
+
1349
+ if (!wfc->isConsole)
1350
+ {
1351
+ instance->VerifyCertificateEx = wf_verify_certificate_ex;
1352
+ instance->VerifyChangedCertificateEx = wf_verify_changed_certificate_ex;
1353
+ instance->PresentGatewayMessage = wf_present_gateway_message;
1354
+ }
1355
+
1356
+ #ifdef WITH_PROGRESS_BAR
1357
+ CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1358
+ CoCreateInstance(&CLSID_TaskbarList, NULL, CLSCTX_ALL, &IID_ITaskbarList3,
1359
+ (void**)&wfc->taskBarList);
1360
+ #endif
1361
+
1362
+ return TRUE;
1363
+ }
1364
+
1365
+ static void wfreerdp_client_free(freerdp* instance, rdpContext* context)
1366
+ {
1367
+ WINPR_UNUSED(instance);
1368
+ if (!context)
1369
+ return;
1370
+
1371
+ #ifdef WITH_PROGRESS_BAR
1372
+ CoUninitialize();
1373
+ #endif
1374
+ }
1375
+
1376
+ static int wfreerdp_client_start(rdpContext* context)
1377
+ {
1378
+ wfContext* wfc = (wfContext*)context;
1379
+
1380
+ WINPR_ASSERT(context);
1381
+ WINPR_ASSERT(context->settings);
1382
+
1383
+ freerdp* instance = context->instance;
1384
+ WINPR_ASSERT(instance);
1385
+
1386
+ rdpSettings* settings = context->settings;
1387
+ WINPR_ASSERT(settings);
1388
+
1389
+ HINSTANCE hInstance = GetModuleHandle(NULL);
1390
+ HWND hWndParent = (HWND)freerdp_settings_get_uint64(settings, FreeRDP_ParentWindowId);
1391
+ if (!freerdp_settings_set_bool(settings, FreeRDP_EmbeddedWindow, (hWndParent) ? TRUE : FALSE))
1392
+ return -1;
1393
+
1394
+ wfc->hWndParent = hWndParent;
1395
+
1396
+ if (freerdp_settings_get_bool(settings, FreeRDP_EmbeddedWindow))
1397
+ {
1398
+ typedef UINT(WINAPI * GetDpiForWindow_t)(HWND hwnd);
1399
+ typedef BOOL(WINAPI * SetProcessDPIAware_t)(void);
1400
+
1401
+ HMODULE module = GetModuleHandle(_T("User32"));
1402
+ if (module)
1403
+ {
1404
+ GetDpiForWindow_t pGetDpiForWindow =
1405
+ GetProcAddressAs(module, "GetDpiForWindow", GetDpiForWindow_t);
1406
+ SetProcessDPIAware_t pSetProcessDPIAware =
1407
+ GetProcAddressAs(module, "SetProcessDPIAware", SetProcessDPIAware_t);
1408
+ if (pGetDpiForWindow && pSetProcessDPIAware)
1409
+ {
1410
+ const UINT dpiAwareness = pGetDpiForWindow(hWndParent);
1411
+ if (dpiAwareness != USER_DEFAULT_SCREEN_DPI)
1412
+ pSetProcessDPIAware();
1413
+ }
1414
+ FreeLibrary(module);
1415
+ }
1416
+ }
1417
+
1418
+ /* initial windows system item position where we will insert new menu item
1419
+ * after default 5 items (restore, move, size, minimize, maximize)
1420
+ * gets incremented each time wf_append_item_to_system_menu is called
1421
+ * or maybe could use GetMenuItemCount() to get initial item count ? */
1422
+ wfc->systemMenuInsertPosition = 6;
1423
+
1424
+ wfc->hInstance = hInstance;
1425
+ wfc->cursor = LoadCursor(NULL, IDC_ARROW);
1426
+ wfc->icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
1427
+ wfc->wndClassName = _tcsdup(_T("FreeRDP"));
1428
+ wfc->wndClass.cbSize = sizeof(WNDCLASSEX);
1429
+ wfc->wndClass.style = CS_HREDRAW | CS_VREDRAW;
1430
+ wfc->wndClass.lpfnWndProc = wf_event_proc;
1431
+ wfc->wndClass.cbClsExtra = 0;
1432
+ wfc->wndClass.cbWndExtra = 0;
1433
+ wfc->wndClass.hCursor = NULL;
1434
+ wfc->wndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
1435
+ wfc->wndClass.lpszMenuName = NULL;
1436
+ wfc->wndClass.lpszClassName = wfc->wndClassName;
1437
+ wfc->wndClass.hInstance = hInstance;
1438
+ wfc->wndClass.hIcon = wfc->icon;
1439
+ wfc->wndClass.hIconSm = wfc->icon;
1440
+ RegisterClassEx(&(wfc->wndClass));
1441
+ wfc->keyboardThread =
1442
+ CreateThread(NULL, 0, wf_keyboard_thread, (void*)wfc, 0, &wfc->keyboardThreadId);
1443
+
1444
+ if (!wfc->keyboardThread)
1445
+ return -1;
1446
+
1447
+ wfc->common.thread =
1448
+ CreateThread(NULL, 0, wf_client_thread, (void*)instance, 0, &wfc->mainThreadId);
1449
+
1450
+ if (!wfc->common.thread)
1451
+ return -1;
1452
+
1453
+ return 0;
1454
+ }
1455
+
1456
+ static int wfreerdp_client_stop(rdpContext* context)
1457
+ {
1458
+ int rc;
1459
+ wfContext* wfc = (wfContext*)context;
1460
+
1461
+ WINPR_ASSERT(wfc);
1462
+ PostThreadMessage(wfc->mainThreadId, WM_QUIT, 0, 0);
1463
+ rc = freerdp_client_common_stop(context);
1464
+ wfc->mainThreadId = 0;
1465
+
1466
+ if (wfc->keyboardThread)
1467
+ {
1468
+ PostThreadMessage(wfc->keyboardThreadId, WM_QUIT, 0, 0);
1469
+ (void)WaitForSingleObject(wfc->keyboardThread, INFINITE);
1470
+ (void)CloseHandle(wfc->keyboardThread);
1471
+ wfc->keyboardThread = NULL;
1472
+ wfc->keyboardThreadId = 0;
1473
+ }
1474
+
1475
+ return 0;
1476
+ }
1477
+
1478
+ int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
1479
+ {
1480
+ pEntryPoints->Version = 1;
1481
+ pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
1482
+ pEntryPoints->GlobalInit = wfreerdp_client_global_init;
1483
+ pEntryPoints->GlobalUninit = wfreerdp_client_global_uninit;
1484
+ pEntryPoints->ContextSize = sizeof(wfContext);
1485
+ pEntryPoints->ClientNew = wfreerdp_client_new;
1486
+ pEntryPoints->ClientFree = wfreerdp_client_free;
1487
+ pEntryPoints->ClientStart = wfreerdp_client_start;
1488
+ pEntryPoints->ClientStop = wfreerdp_client_stop;
1489
+ return 0;
1490
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_client.h ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Windows Client
4
+ *
5
+ * Copyright 2009-2011 Jay Sorg
6
+ * Copyright 2010-2011 Vic Lee
7
+ * Copyright 2010-2011 Marc-Andre Moreau <[email protected]>
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+
22
+ #ifndef FREERDP_CLIENT_WIN_INTERFACE_H
23
+ #define FREERDP_CLIENT_WIN_INTERFACE_H
24
+
25
+ #include <winpr/windows.h>
26
+
27
+ #include <winpr/collections.h>
28
+
29
+ #ifdef WITH_PROGRESS_BAR
30
+ #include <shobjidl.h>
31
+ #endif
32
+
33
+ #include <freerdp/api.h>
34
+ #include <freerdp/freerdp.h>
35
+ #include <freerdp/gdi/gdi.h>
36
+ #include <freerdp/gdi/dc.h>
37
+ #include <freerdp/gdi/region.h>
38
+ #include <freerdp/codec/color.h>
39
+
40
+ #include <freerdp/client/rail.h>
41
+ #include <freerdp/channels/channels.h>
42
+ #include <freerdp/codec/rfx.h>
43
+ #include <freerdp/codec/nsc.h>
44
+ #include <freerdp/client/file.h>
45
+
46
+ #include "wf_channels.h"
47
+ #include "wf_floatbar.h"
48
+ #include "wf_event.h"
49
+ #include "wf_cliprdr.h"
50
+
51
+ #ifdef __cplusplus
52
+ extern "C"
53
+ {
54
+ #endif
55
+
56
+ // System menu constants
57
+ #define SYSCOMMAND_ID_SMARTSIZING 1000
58
+ #define SYSCOMMAND_ID_REQUEST_CONTROL 1001
59
+
60
+ typedef struct
61
+ {
62
+ rdpBitmap _bitmap;
63
+ HDC hdc;
64
+ HBITMAP bitmap;
65
+ HBITMAP org_bitmap;
66
+ BYTE* pdata;
67
+ } wfBitmap;
68
+
69
+ typedef struct
70
+ {
71
+ rdpPointer pointer;
72
+ HCURSOR cursor;
73
+ } wfPointer;
74
+
75
+ struct wf_context
76
+ {
77
+ rdpClientContext common;
78
+
79
+ int offset_x;
80
+ int offset_y;
81
+ int fullscreen_toggle;
82
+ int fullscreen;
83
+ int percentscreen;
84
+ WCHAR* window_title;
85
+ int client_x;
86
+ int client_y;
87
+ int client_width;
88
+ int client_height;
89
+
90
+ HANDLE keyboardThread;
91
+
92
+ HICON icon;
93
+ HWND hWndParent;
94
+ HINSTANCE hInstance;
95
+ WNDCLASSEX wndClass;
96
+ LPCTSTR wndClassName;
97
+ HCURSOR hDefaultCursor;
98
+
99
+ UINT systemMenuInsertPosition;
100
+
101
+ HWND hwnd;
102
+ BOOL is_shown;
103
+ ITaskbarList3* taskBarList;
104
+ POINT diff;
105
+
106
+ wfBitmap* primary;
107
+ wfBitmap* drawing;
108
+ HCURSOR cursor;
109
+ HBRUSH brush;
110
+ HBRUSH org_brush;
111
+ RECT update_rect;
112
+ RECT scale_update_rect;
113
+
114
+ DWORD mainThreadId;
115
+ DWORD keyboardThreadId;
116
+
117
+ rdpFile* connectionRdpFile;
118
+
119
+ BOOL disablewindowtracking;
120
+
121
+ BOOL updating_scrollbars;
122
+ BOOL xScrollVisible;
123
+ int xMinScroll;
124
+ int xCurrentScroll;
125
+ int xMaxScroll;
126
+
127
+ BOOL yScrollVisible;
128
+ int yMinScroll;
129
+ int yCurrentScroll;
130
+ int yMaxScroll;
131
+
132
+ void* clipboard;
133
+ CliprdrClientContext* cliprdr;
134
+
135
+ wfFloatBar* floatbar;
136
+
137
+ RailClientContext* rail;
138
+ wHashTable* railWindows;
139
+ BOOL isConsole;
140
+
141
+ DispClientContext* disp;
142
+ UINT64 lastSentDate;
143
+ BOOL wasMaximized;
144
+ };
145
+
146
+ /**
147
+ * Client Interface
148
+ */
149
+
150
+ FREERDP_API int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints);
151
+ FREERDP_API int freerdp_client_set_window_size(wfContext* wfc, int width, int height);
152
+ FREERDP_API void wf_size_scrollbars(wfContext* wfc, UINT32 client_width, UINT32 client_height);
153
+
154
+ #ifdef __cplusplus
155
+ }
156
+ #endif
157
+
158
+ #endif /* FREERDP_CLIENT_WIN_INTERFACE_H */
local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_cliprdr.c ADDED
@@ -0,0 +1,2549 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Windows Clipboard Redirection
4
+ *
5
+ * Copyright 2012 Jason Champion
6
+ * Copyright 2014 Marc-Andre Moreau <[email protected]>
7
+ * Copyright 2015 Thincast Technologies GmbH
8
+ * Copyright 2015 DI (FH) Martin Haimberger <[email protected]>
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+
23
+ #include <freerdp/config.h>
24
+
25
+ #define CINTERFACE
26
+ #define COBJMACROS
27
+
28
+ #include <ole2.h>
29
+ #include <shlobj.h>
30
+ #include <windows.h>
31
+ #include <winuser.h>
32
+
33
+ #include <winpr/assert.h>
34
+ #include <winpr/library.h>
35
+
36
+ #include <winpr/crt.h>
37
+ #include <winpr/tchar.h>
38
+ #include <winpr/stream.h>
39
+
40
+ #include <freerdp/log.h>
41
+ #include <freerdp/client/cliprdr.h>
42
+
43
+ #include <strsafe.h>
44
+
45
+ #include "wf_cliprdr.h"
46
+
47
+ #define TAG CLIENT_TAG("windows")
48
+
49
+ #ifdef WITH_DEBUG_CLIPRDR
50
+ #define DEBUG_CLIPRDR(...) WLog_DBG(TAG, __VA_ARGS__)
51
+ #else
52
+ #define DEBUG_CLIPRDR(...) \
53
+ do \
54
+ { \
55
+ } while (0)
56
+ #endif
57
+
58
+ typedef BOOL(WINAPI* fnAddClipboardFormatListener)(HWND hwnd);
59
+ typedef BOOL(WINAPI* fnRemoveClipboardFormatListener)(HWND hwnd);
60
+ typedef BOOL(WINAPI* fnGetUpdatedClipboardFormats)(PUINT lpuiFormats, UINT cFormats,
61
+ PUINT pcFormatsOut);
62
+
63
+ typedef struct
64
+ {
65
+ UINT32 remote_format_id;
66
+ UINT32 local_format_id;
67
+ WCHAR* name;
68
+ } formatMapping;
69
+
70
+ typedef struct
71
+ {
72
+ IEnumFORMATETC iEnumFORMATETC;
73
+
74
+ LONG m_lRefCount;
75
+ LONG m_nIndex;
76
+ LONG m_nNumFormats;
77
+ FORMATETC* m_pFormatEtc;
78
+ } CliprdrEnumFORMATETC;
79
+
80
+ typedef struct
81
+ {
82
+ IStream iStream;
83
+
84
+ LONG m_lRefCount;
85
+ ULONG m_lIndex;
86
+ ULARGE_INTEGER m_lSize;
87
+ ULARGE_INTEGER m_lOffset;
88
+ FILEDESCRIPTORW m_Dsc;
89
+ void* m_pData;
90
+ } CliprdrStream;
91
+
92
+ typedef struct
93
+ {
94
+ IDataObject iDataObject;
95
+
96
+ LONG m_lRefCount;
97
+ FORMATETC* m_pFormatEtc;
98
+ STGMEDIUM* m_pStgMedium;
99
+ ULONG m_nNumFormats;
100
+ ULONG m_nStreams;
101
+ IStream** m_pStream;
102
+ void* m_pData;
103
+ } CliprdrDataObject;
104
+
105
+ typedef struct
106
+ {
107
+ wfContext* wfc;
108
+ rdpChannels* channels;
109
+ CliprdrClientContext* context;
110
+
111
+ BOOL sync;
112
+ UINT32 capabilities;
113
+
114
+ size_t map_size;
115
+ size_t map_capacity;
116
+ formatMapping* format_mappings;
117
+
118
+ UINT32 requestedFormatId;
119
+
120
+ HWND hwnd;
121
+ HANDLE hmem;
122
+ HANDLE thread;
123
+ HANDLE response_data_event;
124
+
125
+ LPDATAOBJECT data_obj;
126
+ ULONG req_fsize;
127
+ char* req_fdata;
128
+ HANDLE req_fevent;
129
+
130
+ size_t nFiles;
131
+ size_t file_array_size;
132
+ WCHAR** file_names;
133
+ FILEDESCRIPTORW** fileDescriptor;
134
+
135
+ BOOL legacyApi;
136
+ HMODULE hUser32;
137
+ HWND hWndNextViewer;
138
+ fnAddClipboardFormatListener AddClipboardFormatListener;
139
+ fnRemoveClipboardFormatListener RemoveClipboardFormatListener;
140
+ fnGetUpdatedClipboardFormats GetUpdatedClipboardFormats;
141
+ } wfClipboard;
142
+
143
+ #define WM_CLIPRDR_MESSAGE (WM_USER + 156)
144
+ #define OLE_SETCLIPBOARD 1
145
+
146
+ static BOOL wf_create_file_obj(wfClipboard* cliprdrrdr, IDataObject** ppDataObject);
147
+ static void wf_destroy_file_obj(IDataObject* instance);
148
+ static UINT32 get_remote_format_id(wfClipboard* clipboard, UINT32 local_format);
149
+ static UINT cliprdr_send_data_request(wfClipboard* clipboard, UINT32 format);
150
+ static UINT cliprdr_send_lock(wfClipboard* clipboard);
151
+ static UINT cliprdr_send_unlock(wfClipboard* clipboard);
152
+ static UINT cliprdr_send_request_filecontents(wfClipboard* clipboard, const void* streamid,
153
+ ULONG index, UINT32 flag, UINT64 position,
154
+ ULONG request);
155
+
156
+ static void CliprdrDataObject_Delete(CliprdrDataObject* instance);
157
+
158
+ static CliprdrEnumFORMATETC* CliprdrEnumFORMATETC_New(ULONG nFormats, FORMATETC* pFormatEtc);
159
+ static void CliprdrEnumFORMATETC_Delete(CliprdrEnumFORMATETC* instance);
160
+
161
+ static void CliprdrStream_Delete(CliprdrStream* instance);
162
+
163
+ static BOOL try_open_clipboard(HWND hwnd)
164
+ {
165
+ for (size_t x = 0; x < 10; x++)
166
+ {
167
+ if (OpenClipboard(hwnd))
168
+ return TRUE;
169
+ Sleep(10);
170
+ }
171
+ return FALSE;
172
+ }
173
+
174
+ /**
175
+ * IStream
176
+ */
177
+
178
+ static HRESULT STDMETHODCALLTYPE CliprdrStream_QueryInterface(IStream* This, REFIID riid,
179
+ void** ppvObject)
180
+ {
181
+ if (IsEqualIID(riid, &IID_IStream) || IsEqualIID(riid, &IID_IUnknown))
182
+ {
183
+ IStream_AddRef(This);
184
+ *ppvObject = This;
185
+ return S_OK;
186
+ }
187
+ else
188
+ {
189
+ *ppvObject = 0;
190
+ return E_NOINTERFACE;
191
+ }
192
+ }
193
+
194
+ static ULONG STDMETHODCALLTYPE CliprdrStream_AddRef(IStream* This)
195
+ {
196
+ CliprdrStream* instance = (CliprdrStream*)This;
197
+
198
+ if (!instance)
199
+ return 0;
200
+
201
+ return InterlockedIncrement(&instance->m_lRefCount);
202
+ }
203
+
204
+ static ULONG STDMETHODCALLTYPE CliprdrStream_Release(IStream* This)
205
+ {
206
+ LONG count;
207
+ CliprdrStream* instance = (CliprdrStream*)This;
208
+
209
+ if (!instance)
210
+ return 0;
211
+
212
+ count = InterlockedDecrement(&instance->m_lRefCount);
213
+
214
+ if (count == 0)
215
+ {
216
+ CliprdrStream_Delete(instance);
217
+ return 0;
218
+ }
219
+ else
220
+ {
221
+ return count;
222
+ }
223
+ }
224
+
225
+ static HRESULT STDMETHODCALLTYPE CliprdrStream_Read(IStream* This, void* pv, ULONG cb,
226
+ ULONG* pcbRead)
227
+ {
228
+ int ret;
229
+ CliprdrStream* instance = (CliprdrStream*)This;
230
+ wfClipboard* clipboard;
231
+
232
+ if (!pv || !pcbRead || !instance)
233
+ return E_INVALIDARG;
234
+
235
+ clipboard = (wfClipboard*)instance->m_pData;
236
+ *pcbRead = 0;
237
+
238
+ if (instance->m_lOffset.QuadPart >= instance->m_lSize.QuadPart)
239
+ return S_FALSE;
240
+
241
+ ret = cliprdr_send_request_filecontents(clipboard, (void*)This, instance->m_lIndex,
242
+ FILECONTENTS_RANGE, instance->m_lOffset.QuadPart, cb);
243
+
244
+ if (ret < 0)
245
+ return E_FAIL;
246
+
247
+ if (clipboard->req_fdata)
248
+ {
249
+ CopyMemory(pv, clipboard->req_fdata, clipboard->req_fsize);
250
+ free(clipboard->req_fdata);
251
+ }
252
+
253
+ *pcbRead = clipboard->req_fsize;
254
+ instance->m_lOffset.QuadPart += clipboard->req_fsize;
255
+
256
+ if (clipboard->req_fsize < cb)
257
+ return S_FALSE;
258
+
259
+ return S_OK;
260
+ }
261
+
262
+ static HRESULT STDMETHODCALLTYPE CliprdrStream_Write(IStream* This, const void* pv, ULONG cb,
263
+ ULONG* pcbWritten)
264
+ {
265
+ (void)This;
266
+ (void)pv;
267
+ (void)cb;
268
+ (void)pcbWritten;
269
+ return STG_E_ACCESSDENIED;
270
+ }
271
+
272
+ static HRESULT STDMETHODCALLTYPE CliprdrStream_Seek(IStream* This, LARGE_INTEGER dlibMove,
273
+ DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
274
+ {
275
+ ULONGLONG newoffset;
276
+ CliprdrStream* instance = (CliprdrStream*)This;
277
+
278
+ if (!instance)
279
+ return E_INVALIDARG;
280
+
281
+ newoffset = instance->m_lOffset.QuadPart;
282
+
283
+ switch (dwOrigin)
284
+ {
285
+ case STREAM_SEEK_SET:
286
+ newoffset = dlibMove.QuadPart;
287
+ break;
288
+
289
+ case STREAM_SEEK_CUR:
290
+ newoffset += dlibMove.QuadPart;
291
+ break;
292
+
293
+ case STREAM_SEEK_END:
294
+ newoffset = instance->m_lSize.QuadPart + dlibMove.QuadPart;
295
+ break;
296
+
297
+ default:
298
+ return E_INVALIDARG;
299
+ }
300
+
301
+ if (newoffset < 0 || newoffset >= instance->m_lSize.QuadPart)
302
+ return E_FAIL;
303
+
304
+ instance->m_lOffset.QuadPart = newoffset;
305
+
306
+ if (plibNewPosition)
307
+ plibNewPosition->QuadPart = instance->m_lOffset.QuadPart;
308
+
309
+ return S_OK;
310
+ }
311
+
312
+ static HRESULT STDMETHODCALLTYPE CliprdrStream_SetSize(IStream* This, ULARGE_INTEGER libNewSize)
313
+ {
314
+ (void)This;
315
+ (void)libNewSize;
316
+ return E_NOTIMPL;
317
+ }
318
+
319
+ static HRESULT STDMETHODCALLTYPE CliprdrStream_CopyTo(IStream* This, IStream* pstm,
320
+ ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead,
321
+ ULARGE_INTEGER* pcbWritten)
322
+ {
323
+ (void)This;
324
+ (void)pstm;
325
+ (void)cb;
326
+ (void)pcbRead;
327
+ (void)pcbWritten;
328
+ return E_NOTIMPL;
329
+ }
330
+
331
+ static HRESULT STDMETHODCALLTYPE CliprdrStream_Commit(IStream* This, DWORD grfCommitFlags)
332
+ {
333
+ (void)This;
334
+ (void)grfCommitFlags;
335
+ return E_NOTIMPL;
336
+ }
337
+
338
+ static HRESULT STDMETHODCALLTYPE CliprdrStream_Revert(IStream* This)
339
+ {
340
+ (void)This;
341
+ return E_NOTIMPL;
342
+ }
343
+
344
+ static HRESULT STDMETHODCALLTYPE CliprdrStream_LockRegion(IStream* This, ULARGE_INTEGER libOffset,
345
+ ULARGE_INTEGER cb, DWORD dwLockType)
346
+ {
347
+ (void)This;
348
+ (void)libOffset;
349
+ (void)cb;
350
+ (void)dwLockType;
351
+ return E_NOTIMPL;
352
+ }
353
+
354
+ static HRESULT STDMETHODCALLTYPE CliprdrStream_UnlockRegion(IStream* This, ULARGE_INTEGER libOffset,
355
+ ULARGE_INTEGER cb, DWORD dwLockType)
356
+ {
357
+ (void)This;
358
+ (void)libOffset;
359
+ (void)cb;
360
+ (void)dwLockType;
361
+ return E_NOTIMPL;
362
+ }
363
+
364
+ static HRESULT STDMETHODCALLTYPE CliprdrStream_Stat(IStream* This, STATSTG* pstatstg,
365
+ DWORD grfStatFlag)
366
+ {
367
+ CliprdrStream* instance = (CliprdrStream*)This;
368
+
369
+ if (!instance)
370
+ return E_INVALIDARG;
371
+
372
+ if (pstatstg == NULL)
373
+ return STG_E_INVALIDPOINTER;
374
+
375
+ ZeroMemory(pstatstg, sizeof(STATSTG));
376
+
377
+ switch (grfStatFlag)
378
+ {
379
+ case STATFLAG_DEFAULT:
380
+ return STG_E_INSUFFICIENTMEMORY;
381
+
382
+ case STATFLAG_NONAME:
383
+ pstatstg->cbSize.QuadPart = instance->m_lSize.QuadPart;
384
+ pstatstg->grfLocksSupported = LOCK_EXCLUSIVE;
385
+ pstatstg->grfMode = GENERIC_READ;
386
+ pstatstg->grfStateBits = 0;
387
+ pstatstg->type = STGTY_STREAM;
388
+ break;
389
+
390
+ case STATFLAG_NOOPEN:
391
+ return STG_E_INVALIDFLAG;
392
+
393
+ default:
394
+ return STG_E_INVALIDFLAG;
395
+ }
396
+
397
+ return S_OK;
398
+ }
399
+
400
+ static HRESULT STDMETHODCALLTYPE CliprdrStream_Clone(IStream* This, IStream** ppstm)
401
+ {
402
+ (void)This;
403
+ (void)ppstm;
404
+ return E_NOTIMPL;
405
+ }
406
+
407
+ static CliprdrStream* CliprdrStream_New(ULONG index, void* pData, const FILEDESCRIPTORW* dsc)
408
+ {
409
+ IStream* iStream;
410
+ BOOL success = FALSE;
411
+ BOOL isDir = FALSE;
412
+ CliprdrStream* instance;
413
+ wfClipboard* clipboard = (wfClipboard*)pData;
414
+ instance = (CliprdrStream*)calloc(1, sizeof(CliprdrStream));
415
+
416
+ if (instance)
417
+ {
418
+ instance->m_Dsc = *dsc;
419
+ iStream = &instance->iStream;
420
+ iStream->lpVtbl = (IStreamVtbl*)calloc(1, sizeof(IStreamVtbl));
421
+
422
+ if (iStream->lpVtbl)
423
+ {
424
+ iStream->lpVtbl->QueryInterface = CliprdrStream_QueryInterface;
425
+ iStream->lpVtbl->AddRef = CliprdrStream_AddRef;
426
+ iStream->lpVtbl->Release = CliprdrStream_Release;
427
+ iStream->lpVtbl->Read = CliprdrStream_Read;
428
+ iStream->lpVtbl->Write = CliprdrStream_Write;
429
+ iStream->lpVtbl->Seek = CliprdrStream_Seek;
430
+ iStream->lpVtbl->SetSize = CliprdrStream_SetSize;
431
+ iStream->lpVtbl->CopyTo = CliprdrStream_CopyTo;
432
+ iStream->lpVtbl->Commit = CliprdrStream_Commit;
433
+ iStream->lpVtbl->Revert = CliprdrStream_Revert;
434
+ iStream->lpVtbl->LockRegion = CliprdrStream_LockRegion;
435
+ iStream->lpVtbl->UnlockRegion = CliprdrStream_UnlockRegion;
436
+ iStream->lpVtbl->Stat = CliprdrStream_Stat;
437
+ iStream->lpVtbl->Clone = CliprdrStream_Clone;
438
+ instance->m_lRefCount = 1;
439
+ instance->m_lIndex = index;
440
+ instance->m_pData = pData;
441
+ instance->m_lOffset.QuadPart = 0;
442
+
443
+ if (instance->m_Dsc.dwFlags & FD_ATTRIBUTES)
444
+ {
445
+ if (instance->m_Dsc.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
446
+ isDir = TRUE;
447
+ }
448
+
449
+ if (((instance->m_Dsc.dwFlags & FD_FILESIZE) == 0) && !isDir)
450
+ {
451
+ /* get content size of this stream */
452
+ if (cliprdr_send_request_filecontents(clipboard, (void*)instance,
453
+ instance->m_lIndex, FILECONTENTS_SIZE, 0,
454
+ 8) == CHANNEL_RC_OK)
455
+ {
456
+ success = TRUE;
457
+ }
458
+
459
+ instance->m_lSize.QuadPart = *((LONGLONG*)clipboard->req_fdata);
460
+ free(clipboard->req_fdata);
461
+ }
462
+ else
463
+ {
464
+ instance->m_lSize.QuadPart =
465
+ ((UINT64)instance->m_Dsc.nFileSizeHigh << 32) | instance->m_Dsc.nFileSizeLow;
466
+ success = TRUE;
467
+ }
468
+ }
469
+ }
470
+
471
+ if (!success)
472
+ {
473
+ CliprdrStream_Delete(instance);
474
+ instance = NULL;
475
+ }
476
+
477
+ return instance;
478
+ }
479
+
480
+ void CliprdrStream_Delete(CliprdrStream* instance)
481
+ {
482
+ if (instance)
483
+ {
484
+ free(instance->iStream.lpVtbl);
485
+ free(instance);
486
+ }
487
+ }
488
+
489
+ /**
490
+ * IDataObject
491
+ */
492
+
493
+ static LONG cliprdr_lookup_format(CliprdrDataObject* instance, FORMATETC* pFormatEtc)
494
+ {
495
+ if (!instance || !pFormatEtc)
496
+ return -1;
497
+
498
+ for (ULONG i = 0; i < instance->m_nNumFormats; i++)
499
+ {
500
+ if ((pFormatEtc->tymed & instance->m_pFormatEtc[i].tymed) &&
501
+ pFormatEtc->cfFormat == instance->m_pFormatEtc[i].cfFormat &&
502
+ pFormatEtc->dwAspect & instance->m_pFormatEtc[i].dwAspect)
503
+ {
504
+ return (LONG)i;
505
+ }
506
+ }
507
+
508
+ return -1;
509
+ }
510
+
511
+ static HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryInterface(IDataObject* This, REFIID riid,
512
+ void** ppvObject)
513
+ {
514
+ (void)This;
515
+
516
+ if (!ppvObject)
517
+ return E_INVALIDARG;
518
+
519
+ if (IsEqualIID(riid, &IID_IDataObject) || IsEqualIID(riid, &IID_IUnknown))
520
+ {
521
+ IDataObject_AddRef(This);
522
+ *ppvObject = This;
523
+ return S_OK;
524
+ }
525
+ else
526
+ {
527
+ *ppvObject = 0;
528
+ return E_NOINTERFACE;
529
+ }
530
+ }
531
+
532
+ static ULONG STDMETHODCALLTYPE CliprdrDataObject_AddRef(IDataObject* This)
533
+ {
534
+ CliprdrDataObject* instance = (CliprdrDataObject*)This;
535
+
536
+ if (!instance)
537
+ return E_INVALIDARG;
538
+
539
+ return InterlockedIncrement(&instance->m_lRefCount);
540
+ }
541
+
542
+ static ULONG STDMETHODCALLTYPE CliprdrDataObject_Release(IDataObject* This)
543
+ {
544
+ LONG count;
545
+ CliprdrDataObject* instance = (CliprdrDataObject*)This;
546
+
547
+ if (!instance)
548
+ return E_INVALIDARG;
549
+
550
+ count = InterlockedDecrement(&instance->m_lRefCount);
551
+
552
+ if (count == 0)
553
+ {
554
+ CliprdrDataObject_Delete(instance);
555
+ return 0;
556
+ }
557
+ else
558
+ return count;
559
+ }
560
+
561
+ static HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetData(IDataObject* This, FORMATETC* pFormatEtc,
562
+ STGMEDIUM* pMedium)
563
+ {
564
+ LONG idx;
565
+ CliprdrDataObject* instance = (CliprdrDataObject*)This;
566
+ wfClipboard* clipboard;
567
+
568
+ if (!pFormatEtc || !pMedium || !instance)
569
+ return E_INVALIDARG;
570
+
571
+ clipboard = (wfClipboard*)instance->m_pData;
572
+
573
+ if (!clipboard)
574
+ return E_INVALIDARG;
575
+
576
+ if ((idx = cliprdr_lookup_format(instance, pFormatEtc)) == -1)
577
+ return DV_E_FORMATETC;
578
+
579
+ pMedium->tymed = instance->m_pFormatEtc[idx].tymed;
580
+ pMedium->pUnkForRelease = 0;
581
+
582
+ if (instance->m_pFormatEtc[idx].cfFormat == RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW))
583
+ {
584
+ FILEGROUPDESCRIPTOR* dsc;
585
+ DWORD remote = get_remote_format_id(clipboard, instance->m_pFormatEtc[idx].cfFormat);
586
+
587
+ if (cliprdr_send_data_request(clipboard, remote) != 0)
588
+ return E_UNEXPECTED;
589
+
590
+ pMedium->u.hGlobal = clipboard->hmem;
591
+ /* points to a FILEGROUPDESCRIPTOR structure */
592
+ /* GlobalLock returns a pointer to the first byte of the memory block,
593
+ * in which is a FILEGROUPDESCRIPTOR structure, whose first UINT member
594
+ * is the number of FILEDESCRIPTOR's */
595
+ dsc = (FILEGROUPDESCRIPTOR*)GlobalLock(clipboard->hmem);
596
+ instance->m_nStreams = dsc->cItems;
597
+ GlobalUnlock(clipboard->hmem);
598
+
599
+ if (instance->m_nStreams > 0)
600
+ {
601
+ if (!instance->m_pStream)
602
+ {
603
+ instance->m_pStream = (LPSTREAM*)calloc(instance->m_nStreams, sizeof(LPSTREAM));
604
+
605
+ if (instance->m_pStream)
606
+ {
607
+ for (ULONG i = 0; i < instance->m_nStreams; i++)
608
+ {
609
+ instance->m_pStream[i] =
610
+ (IStream*)CliprdrStream_New(i, clipboard, &dsc->fgd[i]);
611
+
612
+ if (!instance->m_pStream[i])
613
+ return E_OUTOFMEMORY;
614
+ }
615
+ }
616
+ }
617
+ }
618
+
619
+ if (!instance->m_pStream)
620
+ {
621
+ if (clipboard->hmem)
622
+ {
623
+ GlobalFree(clipboard->hmem);
624
+ clipboard->hmem = NULL;
625
+ }
626
+
627
+ pMedium->u.hGlobal = NULL;
628
+ return E_OUTOFMEMORY;
629
+ }
630
+ }
631
+ else if (instance->m_pFormatEtc[idx].cfFormat == RegisterClipboardFormat(CFSTR_FILECONTENTS))
632
+ {
633
+ if ((pFormatEtc->lindex >= 0) && ((ULONG)pFormatEtc->lindex < instance->m_nStreams))
634
+ {
635
+ pMedium->u.pstm = instance->m_pStream[pFormatEtc->lindex];
636
+ IDataObject_AddRef(instance->m_pStream[pFormatEtc->lindex]);
637
+ }
638
+ else
639
+ return E_INVALIDARG;
640
+ }
641
+ else
642
+ return E_UNEXPECTED;
643
+
644
+ return S_OK;
645
+ }
646
+
647
+ static HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetDataHere(IDataObject* This,
648
+ FORMATETC* pformatetc,
649
+ STGMEDIUM* pmedium)
650
+ {
651
+ (void)This;
652
+ (void)pformatetc;
653
+ (void)pmedium;
654
+ return E_NOTIMPL;
655
+ }
656
+
657
+ static HRESULT STDMETHODCALLTYPE CliprdrDataObject_QueryGetData(IDataObject* This,
658
+ FORMATETC* pformatetc)
659
+ {
660
+ CliprdrDataObject* instance = (CliprdrDataObject*)This;
661
+
662
+ if (!pformatetc)
663
+ return E_INVALIDARG;
664
+
665
+ if (cliprdr_lookup_format(instance, pformatetc) == -1)
666
+ return DV_E_FORMATETC;
667
+
668
+ return S_OK;
669
+ }
670
+
671
+ static HRESULT STDMETHODCALLTYPE CliprdrDataObject_GetCanonicalFormatEtc(IDataObject* This,
672
+ FORMATETC* pformatectIn,
673
+ FORMATETC* pformatetcOut)
674
+ {
675
+ (void)This;
676
+ (void)pformatectIn;
677
+
678
+ if (!pformatetcOut)
679
+ return E_INVALIDARG;
680
+
681
+ pformatetcOut->ptd = NULL;
682
+ return E_NOTIMPL;
683
+ }
684
+
685
+ static HRESULT STDMETHODCALLTYPE CliprdrDataObject_SetData(IDataObject* This, FORMATETC* pformatetc,
686
+ STGMEDIUM* pmedium, BOOL fRelease)
687
+ {
688
+ (void)This;
689
+ (void)pformatetc;
690
+ (void)pmedium;
691
+ (void)fRelease;
692
+ return E_NOTIMPL;
693
+ }
694
+
695
+ static HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumFormatEtc(IDataObject* This,
696
+ DWORD dwDirection,
697
+ IEnumFORMATETC** ppenumFormatEtc)
698
+ {
699
+ CliprdrDataObject* instance = (CliprdrDataObject*)This;
700
+
701
+ if (!instance || !ppenumFormatEtc)
702
+ return E_INVALIDARG;
703
+
704
+ if (dwDirection == DATADIR_GET)
705
+ {
706
+ *ppenumFormatEtc = (IEnumFORMATETC*)CliprdrEnumFORMATETC_New(instance->m_nNumFormats,
707
+ instance->m_pFormatEtc);
708
+ return (*ppenumFormatEtc) ? S_OK : E_OUTOFMEMORY;
709
+ }
710
+ else
711
+ {
712
+ return E_NOTIMPL;
713
+ }
714
+ }
715
+
716
+ static HRESULT STDMETHODCALLTYPE CliprdrDataObject_DAdvise(IDataObject* This, FORMATETC* pformatetc,
717
+ DWORD advf, IAdviseSink* pAdvSink,
718
+ DWORD* pdwConnection)
719
+ {
720
+ (void)This;
721
+ (void)pformatetc;
722
+ (void)advf;
723
+ (void)pAdvSink;
724
+ (void)pdwConnection;
725
+ return OLE_E_ADVISENOTSUPPORTED;
726
+ }
727
+
728
+ static HRESULT STDMETHODCALLTYPE CliprdrDataObject_DUnadvise(IDataObject* This, DWORD dwConnection)
729
+ {
730
+ (void)This;
731
+ (void)dwConnection;
732
+ return OLE_E_ADVISENOTSUPPORTED;
733
+ }
734
+
735
+ static HRESULT STDMETHODCALLTYPE CliprdrDataObject_EnumDAdvise(IDataObject* This,
736
+ IEnumSTATDATA** ppenumAdvise)
737
+ {
738
+ (void)This;
739
+ (void)ppenumAdvise;
740
+ return OLE_E_ADVISENOTSUPPORTED;
741
+ }
742
+
743
+ static CliprdrDataObject* CliprdrDataObject_New(FORMATETC* fmtetc, STGMEDIUM* stgmed, ULONG count,
744
+ void* data)
745
+ {
746
+ CliprdrDataObject* instance;
747
+ IDataObject* iDataObject;
748
+ instance = (CliprdrDataObject*)calloc(1, sizeof(CliprdrDataObject));
749
+
750
+ if (!instance)
751
+ goto error;
752
+
753
+ iDataObject = &instance->iDataObject;
754
+ iDataObject->lpVtbl = (IDataObjectVtbl*)calloc(1, sizeof(IDataObjectVtbl));
755
+
756
+ if (!iDataObject->lpVtbl)
757
+ goto error;
758
+
759
+ iDataObject->lpVtbl->QueryInterface = CliprdrDataObject_QueryInterface;
760
+ iDataObject->lpVtbl->AddRef = CliprdrDataObject_AddRef;
761
+ iDataObject->lpVtbl->Release = CliprdrDataObject_Release;
762
+ iDataObject->lpVtbl->GetData = CliprdrDataObject_GetData;
763
+ iDataObject->lpVtbl->GetDataHere = CliprdrDataObject_GetDataHere;
764
+ iDataObject->lpVtbl->QueryGetData = CliprdrDataObject_QueryGetData;
765
+ iDataObject->lpVtbl->GetCanonicalFormatEtc = CliprdrDataObject_GetCanonicalFormatEtc;
766
+ iDataObject->lpVtbl->SetData = CliprdrDataObject_SetData;
767
+ iDataObject->lpVtbl->EnumFormatEtc = CliprdrDataObject_EnumFormatEtc;
768
+ iDataObject->lpVtbl->DAdvise = CliprdrDataObject_DAdvise;
769
+ iDataObject->lpVtbl->DUnadvise = CliprdrDataObject_DUnadvise;
770
+ iDataObject->lpVtbl->EnumDAdvise = CliprdrDataObject_EnumDAdvise;
771
+ instance->m_lRefCount = 1;
772
+ instance->m_nNumFormats = count;
773
+ instance->m_pData = data;
774
+ instance->m_nStreams = 0;
775
+ instance->m_pStream = NULL;
776
+
777
+ if (count > 0)
778
+ {
779
+ instance->m_pFormatEtc = (FORMATETC*)calloc(count, sizeof(FORMATETC));
780
+
781
+ if (!instance->m_pFormatEtc)
782
+ goto error;
783
+
784
+ instance->m_pStgMedium = (STGMEDIUM*)calloc(count, sizeof(STGMEDIUM));
785
+
786
+ if (!instance->m_pStgMedium)
787
+ goto error;
788
+
789
+ for (ULONG i = 0; i < count; i++)
790
+ {
791
+ instance->m_pFormatEtc[i] = fmtetc[i];
792
+ instance->m_pStgMedium[i] = stgmed[i];
793
+ }
794
+ }
795
+
796
+ return instance;
797
+ error:
798
+ CliprdrDataObject_Delete(instance);
799
+ return NULL;
800
+ }
801
+
802
+ void CliprdrDataObject_Delete(CliprdrDataObject* instance)
803
+ {
804
+ if (instance)
805
+ {
806
+ free(instance->iDataObject.lpVtbl);
807
+ free(instance->m_pFormatEtc);
808
+ free(instance->m_pStgMedium);
809
+
810
+ if (instance->m_pStream)
811
+ {
812
+ for (ULONG i = 0; i < instance->m_nStreams; i++)
813
+ CliprdrStream_Release(instance->m_pStream[i]);
814
+
815
+ free(instance->m_pStream);
816
+ }
817
+
818
+ free(instance);
819
+ }
820
+ }
821
+
822
+ static BOOL wf_create_file_obj(wfClipboard* clipboard, IDataObject** ppDataObject)
823
+ {
824
+ FORMATETC fmtetc[2] = { 0 };
825
+ STGMEDIUM stgmeds[2] = { 0 };
826
+
827
+ if (!ppDataObject)
828
+ return FALSE;
829
+
830
+ fmtetc[0].cfFormat = RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW);
831
+ fmtetc[0].dwAspect = DVASPECT_CONTENT;
832
+
833
+ fmtetc[0].tymed = TYMED_HGLOBAL;
834
+ stgmeds[0].tymed = TYMED_HGLOBAL;
835
+
836
+ fmtetc[1].cfFormat = RegisterClipboardFormat(CFSTR_FILECONTENTS);
837
+ fmtetc[1].dwAspect = DVASPECT_CONTENT;
838
+
839
+ fmtetc[1].tymed = TYMED_ISTREAM;
840
+ stgmeds[1].tymed = TYMED_ISTREAM;
841
+
842
+ *ppDataObject = (IDataObject*)CliprdrDataObject_New(fmtetc, stgmeds, 2, clipboard);
843
+ return (*ppDataObject) ? TRUE : FALSE;
844
+ }
845
+
846
+ static void wf_destroy_file_obj(IDataObject* instance)
847
+ {
848
+ if (instance)
849
+ IDataObject_Release(instance);
850
+ }
851
+
852
+ /**
853
+ * IEnumFORMATETC
854
+ */
855
+
856
+ static void cliprdr_format_deep_copy(FORMATETC* dest, FORMATETC* source)
857
+ {
858
+ *dest = *source;
859
+
860
+ if (source->ptd)
861
+ {
862
+ dest->ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE));
863
+
864
+ if (dest->ptd)
865
+ *(dest->ptd) = *(source->ptd);
866
+ }
867
+ }
868
+
869
+ static HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_QueryInterface(IEnumFORMATETC* This,
870
+ REFIID riid, void** ppvObject)
871
+ {
872
+ (void)This;
873
+
874
+ if (IsEqualIID(riid, &IID_IEnumFORMATETC) || IsEqualIID(riid, &IID_IUnknown))
875
+ {
876
+ IEnumFORMATETC_AddRef(This);
877
+ *ppvObject = This;
878
+ return S_OK;
879
+ }
880
+ else
881
+ {
882
+ *ppvObject = 0;
883
+ return E_NOINTERFACE;
884
+ }
885
+ }
886
+
887
+ static ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_AddRef(IEnumFORMATETC* This)
888
+ {
889
+ CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*)This;
890
+
891
+ if (!instance)
892
+ return 0;
893
+
894
+ return InterlockedIncrement(&instance->m_lRefCount);
895
+ }
896
+
897
+ static ULONG STDMETHODCALLTYPE CliprdrEnumFORMATETC_Release(IEnumFORMATETC* This)
898
+ {
899
+ LONG count;
900
+ CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*)This;
901
+
902
+ if (!instance)
903
+ return 0;
904
+
905
+ count = InterlockedDecrement(&instance->m_lRefCount);
906
+
907
+ if (count == 0)
908
+ {
909
+ CliprdrEnumFORMATETC_Delete(instance);
910
+ return 0;
911
+ }
912
+ else
913
+ {
914
+ return count;
915
+ }
916
+ }
917
+
918
+ static HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Next(IEnumFORMATETC* This, ULONG celt,
919
+ FORMATETC* rgelt, ULONG* pceltFetched)
920
+ {
921
+ ULONG copied = 0;
922
+ CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*)This;
923
+
924
+ if (!instance || !celt || !rgelt)
925
+ return E_INVALIDARG;
926
+
927
+ while ((instance->m_nIndex < instance->m_nNumFormats) && (copied < celt))
928
+ {
929
+ cliprdr_format_deep_copy(&rgelt[copied++], &instance->m_pFormatEtc[instance->m_nIndex++]);
930
+ }
931
+
932
+ if (pceltFetched != 0)
933
+ *pceltFetched = copied;
934
+
935
+ return (copied == celt) ? S_OK : E_FAIL;
936
+ }
937
+
938
+ static HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Skip(IEnumFORMATETC* This, ULONG celt)
939
+ {
940
+ CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*)This;
941
+
942
+ if (!instance)
943
+ return E_INVALIDARG;
944
+
945
+ if (instance->m_nIndex + (LONG)celt > instance->m_nNumFormats)
946
+ return E_FAIL;
947
+
948
+ instance->m_nIndex += celt;
949
+ return S_OK;
950
+ }
951
+
952
+ static HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Reset(IEnumFORMATETC* This)
953
+ {
954
+ CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*)This;
955
+
956
+ if (!instance)
957
+ return E_INVALIDARG;
958
+
959
+ instance->m_nIndex = 0;
960
+ return S_OK;
961
+ }
962
+
963
+ static HRESULT STDMETHODCALLTYPE CliprdrEnumFORMATETC_Clone(IEnumFORMATETC* This,
964
+ IEnumFORMATETC** ppEnum)
965
+ {
966
+ CliprdrEnumFORMATETC* instance = (CliprdrEnumFORMATETC*)This;
967
+
968
+ if (!instance || !ppEnum)
969
+ return E_INVALIDARG;
970
+
971
+ *ppEnum =
972
+ (IEnumFORMATETC*)CliprdrEnumFORMATETC_New(instance->m_nNumFormats, instance->m_pFormatEtc);
973
+
974
+ if (!*ppEnum)
975
+ return E_OUTOFMEMORY;
976
+
977
+ ((CliprdrEnumFORMATETC*)*ppEnum)->m_nIndex = instance->m_nIndex;
978
+ return S_OK;
979
+ }
980
+
981
+ CliprdrEnumFORMATETC* CliprdrEnumFORMATETC_New(ULONG nFormats, FORMATETC* pFormatEtc)
982
+ {
983
+ CliprdrEnumFORMATETC* instance;
984
+ IEnumFORMATETC* iEnumFORMATETC;
985
+
986
+ if ((nFormats != 0) && !pFormatEtc)
987
+ return NULL;
988
+
989
+ instance = (CliprdrEnumFORMATETC*)calloc(1, sizeof(CliprdrEnumFORMATETC));
990
+
991
+ if (!instance)
992
+ goto error;
993
+
994
+ iEnumFORMATETC = &instance->iEnumFORMATETC;
995
+ iEnumFORMATETC->lpVtbl = (IEnumFORMATETCVtbl*)calloc(1, sizeof(IEnumFORMATETCVtbl));
996
+
997
+ if (!iEnumFORMATETC->lpVtbl)
998
+ goto error;
999
+
1000
+ iEnumFORMATETC->lpVtbl->QueryInterface = CliprdrEnumFORMATETC_QueryInterface;
1001
+ iEnumFORMATETC->lpVtbl->AddRef = CliprdrEnumFORMATETC_AddRef;
1002
+ iEnumFORMATETC->lpVtbl->Release = CliprdrEnumFORMATETC_Release;
1003
+ iEnumFORMATETC->lpVtbl->Next = CliprdrEnumFORMATETC_Next;
1004
+ iEnumFORMATETC->lpVtbl->Skip = CliprdrEnumFORMATETC_Skip;
1005
+ iEnumFORMATETC->lpVtbl->Reset = CliprdrEnumFORMATETC_Reset;
1006
+ iEnumFORMATETC->lpVtbl->Clone = CliprdrEnumFORMATETC_Clone;
1007
+ instance->m_lRefCount = 1;
1008
+ instance->m_nIndex = 0;
1009
+ instance->m_nNumFormats = nFormats;
1010
+
1011
+ if (nFormats > 0)
1012
+ {
1013
+ instance->m_pFormatEtc = (FORMATETC*)calloc(nFormats, sizeof(FORMATETC));
1014
+
1015
+ if (!instance->m_pFormatEtc)
1016
+ goto error;
1017
+
1018
+ for (ULONG i = 0; i < nFormats; i++)
1019
+ cliprdr_format_deep_copy(&instance->m_pFormatEtc[i], &pFormatEtc[i]);
1020
+ }
1021
+
1022
+ return instance;
1023
+ error:
1024
+ CliprdrEnumFORMATETC_Delete(instance);
1025
+ return NULL;
1026
+ }
1027
+
1028
+ void CliprdrEnumFORMATETC_Delete(CliprdrEnumFORMATETC* instance)
1029
+ {
1030
+ if (instance)
1031
+ {
1032
+ free(instance->iEnumFORMATETC.lpVtbl);
1033
+
1034
+ if (instance->m_pFormatEtc)
1035
+ {
1036
+ for (LONG i = 0; i < instance->m_nNumFormats; i++)
1037
+ {
1038
+ if (instance->m_pFormatEtc[i].ptd)
1039
+ CoTaskMemFree(instance->m_pFormatEtc[i].ptd);
1040
+ }
1041
+
1042
+ free(instance->m_pFormatEtc);
1043
+ }
1044
+
1045
+ free(instance);
1046
+ }
1047
+ }
1048
+
1049
+ /***********************************************************************************/
1050
+
1051
+ static UINT32 get_local_format_id_by_name(wfClipboard* clipboard, const TCHAR* format_name)
1052
+ {
1053
+ formatMapping* map;
1054
+ WCHAR* unicode_name;
1055
+ #if !defined(UNICODE)
1056
+ size_t size;
1057
+ #endif
1058
+
1059
+ if (!clipboard || !format_name)
1060
+ return 0;
1061
+
1062
+ #if defined(UNICODE)
1063
+ unicode_name = _wcsdup(format_name);
1064
+ #else
1065
+ size = _tcslen(format_name);
1066
+ unicode_name = calloc(size + 1, sizeof(WCHAR));
1067
+
1068
+ if (!unicode_name)
1069
+ return 0;
1070
+
1071
+ MultiByteToWideChar(CP_OEMCP, 0, format_name, strlen(format_name), unicode_name, size);
1072
+ #endif
1073
+
1074
+ if (!unicode_name)
1075
+ return 0;
1076
+
1077
+ for (size_t i = 0; i < clipboard->map_size; i++)
1078
+ {
1079
+ map = &clipboard->format_mappings[i];
1080
+
1081
+ if (map->name)
1082
+ {
1083
+ if (wcscmp(map->name, unicode_name) == 0)
1084
+ {
1085
+ free(unicode_name);
1086
+ return map->local_format_id;
1087
+ }
1088
+ }
1089
+ }
1090
+
1091
+ free(unicode_name);
1092
+ return 0;
1093
+ }
1094
+
1095
+ static INLINE BOOL file_transferring(wfClipboard* clipboard)
1096
+ {
1097
+ return get_local_format_id_by_name(clipboard, CFSTR_FILEDESCRIPTORW) ? TRUE : FALSE;
1098
+ }
1099
+
1100
+ static UINT32 get_remote_format_id(wfClipboard* clipboard, UINT32 local_format)
1101
+ {
1102
+ formatMapping* map;
1103
+
1104
+ if (!clipboard)
1105
+ return 0;
1106
+
1107
+ for (UINT32 i = 0; i < clipboard->map_size; i++)
1108
+ {
1109
+ map = &clipboard->format_mappings[i];
1110
+
1111
+ if (map->local_format_id == local_format)
1112
+ return map->remote_format_id;
1113
+ }
1114
+
1115
+ return local_format;
1116
+ }
1117
+
1118
+ static void map_ensure_capacity(wfClipboard* clipboard)
1119
+ {
1120
+ if (!clipboard)
1121
+ return;
1122
+
1123
+ if (clipboard->map_size >= clipboard->map_capacity)
1124
+ {
1125
+ size_t new_size;
1126
+ formatMapping* new_map;
1127
+ new_size = clipboard->map_capacity * 2;
1128
+ new_map =
1129
+ (formatMapping*)realloc(clipboard->format_mappings, sizeof(formatMapping) * new_size);
1130
+
1131
+ if (!new_map)
1132
+ return;
1133
+
1134
+ clipboard->format_mappings = new_map;
1135
+ clipboard->map_capacity = new_size;
1136
+ }
1137
+ }
1138
+
1139
+ static BOOL clear_format_map(wfClipboard* clipboard)
1140
+ {
1141
+ formatMapping* map;
1142
+
1143
+ if (!clipboard)
1144
+ return FALSE;
1145
+
1146
+ if (clipboard->format_mappings)
1147
+ {
1148
+ for (size_t i = 0; i < clipboard->map_capacity; i++)
1149
+ {
1150
+ map = &clipboard->format_mappings[i];
1151
+ map->remote_format_id = 0;
1152
+ map->local_format_id = 0;
1153
+ free(map->name);
1154
+ map->name = NULL;
1155
+ }
1156
+ }
1157
+
1158
+ clipboard->map_size = 0;
1159
+ return TRUE;
1160
+ }
1161
+
1162
+ static UINT cliprdr_send_tempdir(wfClipboard* clipboard)
1163
+ {
1164
+ CLIPRDR_TEMP_DIRECTORY tempDirectory;
1165
+
1166
+ if (!clipboard)
1167
+ return -1;
1168
+
1169
+ if (GetEnvironmentVariableA("TEMP", tempDirectory.szTempDir, sizeof(tempDirectory.szTempDir)) ==
1170
+ 0)
1171
+ return -1;
1172
+
1173
+ return clipboard->context->TempDirectory(clipboard->context, &tempDirectory);
1174
+ }
1175
+
1176
+ static BOOL cliprdr_GetUpdatedClipboardFormats(wfClipboard* clipboard, PUINT lpuiFormats,
1177
+ UINT cFormats, PUINT pcFormatsOut)
1178
+ {
1179
+ UINT index = 0;
1180
+ UINT format = 0;
1181
+ BOOL clipboardOpen = FALSE;
1182
+
1183
+ if (!clipboard->legacyApi)
1184
+ return clipboard->GetUpdatedClipboardFormats(lpuiFormats, cFormats, pcFormatsOut);
1185
+
1186
+ clipboardOpen = try_open_clipboard(clipboard->hwnd);
1187
+
1188
+ if (!clipboardOpen)
1189
+ {
1190
+ *pcFormatsOut = 0;
1191
+ return TRUE; /* Other app holding clipboard */
1192
+ }
1193
+
1194
+ while (index < cFormats)
1195
+ {
1196
+ format = EnumClipboardFormats(format);
1197
+
1198
+ if (!format)
1199
+ break;
1200
+
1201
+ lpuiFormats[index] = format;
1202
+ index++;
1203
+ }
1204
+
1205
+ *pcFormatsOut = index;
1206
+ CloseClipboard();
1207
+ return TRUE;
1208
+ }
1209
+
1210
+ static UINT cliprdr_send_format_list(wfClipboard* clipboard)
1211
+ {
1212
+ UINT rc;
1213
+ int count = 0;
1214
+ UINT32 numFormats = 0;
1215
+ UINT32 formatId = 0;
1216
+ char formatName[1024];
1217
+ CLIPRDR_FORMAT* formats = NULL;
1218
+ CLIPRDR_FORMAT_LIST formatList = { 0 };
1219
+
1220
+ if (!clipboard)
1221
+ return ERROR_INTERNAL_ERROR;
1222
+
1223
+ /* Ignore if other app is holding clipboard */
1224
+ if (try_open_clipboard(clipboard->hwnd))
1225
+ {
1226
+ count = CountClipboardFormats();
1227
+ numFormats = (UINT32)count;
1228
+ formats = (CLIPRDR_FORMAT*)calloc(numFormats, sizeof(CLIPRDR_FORMAT));
1229
+
1230
+ if (!formats)
1231
+ {
1232
+ CloseClipboard();
1233
+ return CHANNEL_RC_NO_MEMORY;
1234
+ }
1235
+
1236
+ {
1237
+ UINT32 index = 0;
1238
+
1239
+ if (IsClipboardFormatAvailable(CF_HDROP))
1240
+ {
1241
+ formats[index++].formatId = RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW);
1242
+ formats[index++].formatId = RegisterClipboardFormat(CFSTR_FILECONTENTS);
1243
+ }
1244
+ else
1245
+ {
1246
+ while ((formatId = EnumClipboardFormats(formatId)) != 0)
1247
+ formats[index++].formatId = formatId;
1248
+ }
1249
+
1250
+ numFormats = index;
1251
+ }
1252
+
1253
+ if (!CloseClipboard())
1254
+ {
1255
+ free(formats);
1256
+ return ERROR_INTERNAL_ERROR;
1257
+ }
1258
+
1259
+ for (UINT index = 0; index < numFormats; index++)
1260
+ {
1261
+ if (GetClipboardFormatNameA(formats[index].formatId, formatName, sizeof(formatName)))
1262
+ {
1263
+ formats[index].formatName = _strdup(formatName);
1264
+ }
1265
+ }
1266
+ }
1267
+
1268
+ formatList.numFormats = numFormats;
1269
+ formatList.formats = formats;
1270
+ formatList.common.msgType = CB_FORMAT_LIST;
1271
+ rc = clipboard->context->ClientFormatList(clipboard->context, &formatList);
1272
+
1273
+ for (UINT index = 0; index < numFormats; index++)
1274
+ free(formats[index].formatName);
1275
+
1276
+ free(formats);
1277
+ return rc;
1278
+ }
1279
+
1280
+ static UINT cliprdr_send_data_request(wfClipboard* clipboard, UINT32 formatId)
1281
+ {
1282
+ UINT rc;
1283
+ UINT32 remoteFormatId;
1284
+ CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest;
1285
+
1286
+ if (!clipboard || !clipboard->context || !clipboard->context->ClientFormatDataRequest)
1287
+ return ERROR_INTERNAL_ERROR;
1288
+
1289
+ remoteFormatId = get_remote_format_id(clipboard, formatId);
1290
+
1291
+ formatDataRequest.requestedFormatId = remoteFormatId;
1292
+ clipboard->requestedFormatId = formatId;
1293
+ rc = clipboard->context->ClientFormatDataRequest(clipboard->context, &formatDataRequest);
1294
+
1295
+ if (WaitForSingleObject(clipboard->response_data_event, INFINITE) != WAIT_OBJECT_0)
1296
+ rc = ERROR_INTERNAL_ERROR;
1297
+ else if (!ResetEvent(clipboard->response_data_event))
1298
+ rc = ERROR_INTERNAL_ERROR;
1299
+
1300
+ return rc;
1301
+ }
1302
+
1303
+ UINT cliprdr_send_request_filecontents(wfClipboard* clipboard, const void* streamid, ULONG index,
1304
+ UINT32 flag, UINT64 position, ULONG nreq)
1305
+ {
1306
+ UINT rc;
1307
+ CLIPRDR_FILE_CONTENTS_REQUEST fileContentsRequest;
1308
+
1309
+ if (!clipboard || !clipboard->context || !clipboard->context->ClientFileContentsRequest)
1310
+ return ERROR_INTERNAL_ERROR;
1311
+
1312
+ fileContentsRequest.streamId = (UINT32)(ULONG_PTR)streamid;
1313
+ fileContentsRequest.listIndex = index;
1314
+ fileContentsRequest.dwFlags = flag;
1315
+ fileContentsRequest.nPositionLow = position & 0xFFFFFFFF;
1316
+ fileContentsRequest.nPositionHigh = (position >> 32) & 0xFFFFFFFF;
1317
+ fileContentsRequest.cbRequested = nreq;
1318
+ fileContentsRequest.clipDataId = 0;
1319
+ fileContentsRequest.common.msgFlags = 0;
1320
+ rc = clipboard->context->ClientFileContentsRequest(clipboard->context, &fileContentsRequest);
1321
+
1322
+ if (WaitForSingleObject(clipboard->req_fevent, INFINITE) != WAIT_OBJECT_0)
1323
+ rc = ERROR_INTERNAL_ERROR;
1324
+ else if (!ResetEvent(clipboard->req_fevent))
1325
+ rc = ERROR_INTERNAL_ERROR;
1326
+
1327
+ return rc;
1328
+ }
1329
+
1330
+ static UINT cliprdr_send_response_filecontents(wfClipboard* clipboard, UINT32 streamId, UINT32 size,
1331
+ BYTE* data)
1332
+ {
1333
+ CLIPRDR_FILE_CONTENTS_RESPONSE fileContentsResponse;
1334
+
1335
+ if (!clipboard || !clipboard->context || !clipboard->context->ClientFileContentsResponse)
1336
+ return ERROR_INTERNAL_ERROR;
1337
+
1338
+ fileContentsResponse.streamId = streamId;
1339
+ fileContentsResponse.cbRequested = size;
1340
+ fileContentsResponse.requestedData = data;
1341
+ fileContentsResponse.common.msgFlags = CB_RESPONSE_OK;
1342
+ return clipboard->context->ClientFileContentsResponse(clipboard->context,
1343
+ &fileContentsResponse);
1344
+ }
1345
+
1346
+ static LRESULT CALLBACK cliprdr_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
1347
+ {
1348
+ static wfClipboard* clipboard = NULL;
1349
+
1350
+ switch (Msg)
1351
+ {
1352
+ case WM_CREATE:
1353
+ DEBUG_CLIPRDR("info: WM_CREATE");
1354
+ clipboard = (wfClipboard*)((CREATESTRUCT*)lParam)->lpCreateParams;
1355
+ clipboard->hwnd = hWnd;
1356
+
1357
+ if (!clipboard->legacyApi)
1358
+ clipboard->AddClipboardFormatListener(hWnd);
1359
+ else
1360
+ clipboard->hWndNextViewer = SetClipboardViewer(hWnd);
1361
+
1362
+ break;
1363
+
1364
+ case WM_CLOSE:
1365
+ DEBUG_CLIPRDR("info: WM_CLOSE");
1366
+
1367
+ if (!clipboard->legacyApi)
1368
+ clipboard->RemoveClipboardFormatListener(hWnd);
1369
+
1370
+ break;
1371
+
1372
+ case WM_DESTROY:
1373
+ if (clipboard->legacyApi)
1374
+ ChangeClipboardChain(hWnd, clipboard->hWndNextViewer);
1375
+
1376
+ break;
1377
+
1378
+ case WM_CLIPBOARDUPDATE:
1379
+ DEBUG_CLIPRDR("info: WM_CLIPBOARDUPDATE");
1380
+
1381
+ if (clipboard->sync)
1382
+ {
1383
+ if ((GetClipboardOwner() != clipboard->hwnd) &&
1384
+ (S_FALSE == OleIsCurrentClipboard(clipboard->data_obj)))
1385
+ {
1386
+ if (clipboard->hmem)
1387
+ {
1388
+ GlobalFree(clipboard->hmem);
1389
+ clipboard->hmem = NULL;
1390
+ }
1391
+
1392
+ cliprdr_send_format_list(clipboard);
1393
+ }
1394
+ }
1395
+
1396
+ break;
1397
+
1398
+ case WM_RENDERALLFORMATS:
1399
+ DEBUG_CLIPRDR("info: WM_RENDERALLFORMATS");
1400
+
1401
+ /* discard all contexts in clipboard */
1402
+ if (!try_open_clipboard(clipboard->hwnd))
1403
+ {
1404
+ DEBUG_CLIPRDR("OpenClipboard failed with 0x%x", GetLastError());
1405
+ break;
1406
+ }
1407
+
1408
+ EmptyClipboard();
1409
+ CloseClipboard();
1410
+ break;
1411
+
1412
+ case WM_RENDERFORMAT:
1413
+ DEBUG_CLIPRDR("info: WM_RENDERFORMAT");
1414
+
1415
+ if (cliprdr_send_data_request(clipboard, (UINT32)wParam) != 0)
1416
+ {
1417
+ DEBUG_CLIPRDR("error: cliprdr_send_data_request failed.");
1418
+ break;
1419
+ }
1420
+
1421
+ if (!SetClipboardData((UINT)wParam, clipboard->hmem))
1422
+ {
1423
+ DEBUG_CLIPRDR("SetClipboardData failed with 0x%x", GetLastError());
1424
+
1425
+ if (clipboard->hmem)
1426
+ {
1427
+ GlobalFree(clipboard->hmem);
1428
+ clipboard->hmem = NULL;
1429
+ }
1430
+ }
1431
+
1432
+ /* Note: GlobalFree() is not needed when success */
1433
+ break;
1434
+
1435
+ case WM_DRAWCLIPBOARD:
1436
+ if (clipboard->legacyApi)
1437
+ {
1438
+ if ((GetClipboardOwner() != clipboard->hwnd) &&
1439
+ (S_FALSE == OleIsCurrentClipboard(clipboard->data_obj)))
1440
+ {
1441
+ cliprdr_send_format_list(clipboard);
1442
+ }
1443
+
1444
+ SendMessage(clipboard->hWndNextViewer, Msg, wParam, lParam);
1445
+ }
1446
+
1447
+ break;
1448
+
1449
+ case WM_CHANGECBCHAIN:
1450
+ if (clipboard->legacyApi)
1451
+ {
1452
+ HWND hWndCurrViewer = (HWND)wParam;
1453
+ HWND hWndNextViewer = (HWND)lParam;
1454
+
1455
+ if (hWndCurrViewer == clipboard->hWndNextViewer)
1456
+ clipboard->hWndNextViewer = hWndNextViewer;
1457
+ else if (clipboard->hWndNextViewer)
1458
+ SendMessage(clipboard->hWndNextViewer, Msg, wParam, lParam);
1459
+ }
1460
+
1461
+ break;
1462
+
1463
+ case WM_CLIPRDR_MESSAGE:
1464
+ DEBUG_CLIPRDR("info: WM_CLIPRDR_MESSAGE");
1465
+
1466
+ switch (wParam)
1467
+ {
1468
+ case OLE_SETCLIPBOARD:
1469
+ DEBUG_CLIPRDR("info: OLE_SETCLIPBOARD");
1470
+
1471
+ if (wf_create_file_obj(clipboard, &clipboard->data_obj))
1472
+ {
1473
+ if (OleSetClipboard(clipboard->data_obj) != S_OK)
1474
+ {
1475
+ wf_destroy_file_obj(clipboard->data_obj);
1476
+ clipboard->data_obj = NULL;
1477
+ }
1478
+ }
1479
+
1480
+ break;
1481
+
1482
+ default:
1483
+ break;
1484
+ }
1485
+
1486
+ break;
1487
+
1488
+ case WM_DESTROYCLIPBOARD:
1489
+ case WM_ASKCBFORMATNAME:
1490
+ case WM_HSCROLLCLIPBOARD:
1491
+ case WM_PAINTCLIPBOARD:
1492
+ case WM_SIZECLIPBOARD:
1493
+ case WM_VSCROLLCLIPBOARD:
1494
+ default:
1495
+ return DefWindowProc(hWnd, Msg, wParam, lParam);
1496
+ }
1497
+
1498
+ return 0;
1499
+ }
1500
+
1501
+ static int create_cliprdr_window(wfClipboard* clipboard)
1502
+ {
1503
+ WNDCLASSEX wnd_cls = { 0 };
1504
+
1505
+ wnd_cls.cbSize = sizeof(WNDCLASSEX);
1506
+ wnd_cls.style = CS_OWNDC;
1507
+ wnd_cls.lpfnWndProc = cliprdr_proc;
1508
+ wnd_cls.cbClsExtra = 0;
1509
+ wnd_cls.cbWndExtra = 0;
1510
+ wnd_cls.hIcon = NULL;
1511
+ wnd_cls.hCursor = NULL;
1512
+ wnd_cls.hbrBackground = NULL;
1513
+ wnd_cls.lpszMenuName = NULL;
1514
+ wnd_cls.lpszClassName = _T("ClipboardHiddenMessageProcessor");
1515
+ wnd_cls.hInstance = GetModuleHandle(NULL);
1516
+ wnd_cls.hIconSm = NULL;
1517
+ RegisterClassEx(&wnd_cls);
1518
+ clipboard->hwnd =
1519
+ CreateWindowEx(WS_EX_LEFT, _T("ClipboardHiddenMessageProcessor"), _T("rdpclip"), 0, 0, 0, 0,
1520
+ 0, HWND_MESSAGE, NULL, GetModuleHandle(NULL), clipboard);
1521
+
1522
+ if (!clipboard->hwnd)
1523
+ {
1524
+ DEBUG_CLIPRDR("error: CreateWindowEx failed with %x.", GetLastError());
1525
+ return -1;
1526
+ }
1527
+
1528
+ return 0;
1529
+ }
1530
+
1531
+ static DWORD WINAPI cliprdr_thread_func(LPVOID arg)
1532
+ {
1533
+ int ret;
1534
+ MSG msg;
1535
+ BOOL mcode;
1536
+ wfClipboard* clipboard = (wfClipboard*)arg;
1537
+ OleInitialize(0);
1538
+
1539
+ if ((ret = create_cliprdr_window(clipboard)) != 0)
1540
+ {
1541
+ OleUninitialize();
1542
+ DEBUG_CLIPRDR("error: create clipboard window failed.");
1543
+ return 0;
1544
+ }
1545
+
1546
+ while ((mcode = GetMessage(&msg, 0, 0, 0)) != 0)
1547
+ {
1548
+ if (mcode == -1)
1549
+ {
1550
+ DEBUG_CLIPRDR("error: clipboard thread GetMessage failed.");
1551
+ break;
1552
+ }
1553
+ else
1554
+ {
1555
+ TranslateMessage(&msg);
1556
+ DispatchMessage(&msg);
1557
+ }
1558
+ }
1559
+
1560
+ OleUninitialize();
1561
+ return 0;
1562
+ }
1563
+
1564
+ static void clear_file_array(wfClipboard* clipboard)
1565
+ {
1566
+ if (!clipboard)
1567
+ return;
1568
+
1569
+ /* clear file_names array */
1570
+ if (clipboard->file_names)
1571
+ {
1572
+ for (size_t i = 0; i < clipboard->nFiles; i++)
1573
+ {
1574
+ free(clipboard->file_names[i]);
1575
+ clipboard->file_names[i] = NULL;
1576
+ }
1577
+
1578
+ free(clipboard->file_names);
1579
+ clipboard->file_names = NULL;
1580
+ }
1581
+
1582
+ /* clear fileDescriptor array */
1583
+ if (clipboard->fileDescriptor)
1584
+ {
1585
+ for (size_t i = 0; i < clipboard->nFiles; i++)
1586
+ {
1587
+ free(clipboard->fileDescriptor[i]);
1588
+ clipboard->fileDescriptor[i] = NULL;
1589
+ }
1590
+
1591
+ free(clipboard->fileDescriptor);
1592
+ clipboard->fileDescriptor = NULL;
1593
+ }
1594
+
1595
+ clipboard->file_array_size = 0;
1596
+ clipboard->nFiles = 0;
1597
+ }
1598
+
1599
+ static BOOL wf_cliprdr_get_file_contents(WCHAR* file_name, BYTE* buffer, LONG positionLow,
1600
+ LONG positionHigh, DWORD nRequested, DWORD* puSize)
1601
+ {
1602
+ BOOL res = FALSE;
1603
+ HANDLE hFile;
1604
+ DWORD nGet, rc;
1605
+
1606
+ if (!file_name || !buffer || !puSize)
1607
+ {
1608
+ WLog_ERR(TAG, "get file contents Invalid Arguments.");
1609
+ return FALSE;
1610
+ }
1611
+
1612
+ hFile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
1613
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL);
1614
+
1615
+ if (hFile == INVALID_HANDLE_VALUE)
1616
+ return FALSE;
1617
+
1618
+ rc = SetFilePointer(hFile, positionLow, &positionHigh, FILE_BEGIN);
1619
+
1620
+ if (rc == INVALID_SET_FILE_POINTER)
1621
+ goto error;
1622
+
1623
+ if (!ReadFile(hFile, buffer, nRequested, &nGet, NULL))
1624
+ {
1625
+ DEBUG_CLIPRDR("ReadFile failed with 0x%08lX.", GetLastError());
1626
+ goto error;
1627
+ }
1628
+
1629
+ res = TRUE;
1630
+ error:
1631
+
1632
+ if (!CloseHandle(hFile))
1633
+ res = FALSE;
1634
+
1635
+ if (res)
1636
+ *puSize = nGet;
1637
+
1638
+ return res;
1639
+ }
1640
+
1641
+ /* path_name has a '\' at the end. e.g. c:\newfolder\, file_name is c:\newfolder\new.txt */
1642
+ static FILEDESCRIPTORW* wf_cliprdr_get_file_descriptor(WCHAR* file_name, size_t pathLen)
1643
+ {
1644
+ HANDLE hFile;
1645
+ FILEDESCRIPTORW* fd;
1646
+ fd = (FILEDESCRIPTORW*)calloc(1, sizeof(FILEDESCRIPTORW));
1647
+
1648
+ if (!fd)
1649
+ return NULL;
1650
+
1651
+ hFile = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
1652
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL);
1653
+
1654
+ if (hFile == INVALID_HANDLE_VALUE)
1655
+ {
1656
+ free(fd);
1657
+ return NULL;
1658
+ }
1659
+
1660
+ fd->dwFlags = FD_ATTRIBUTES | FD_FILESIZE | FD_WRITESTIME | FD_PROGRESSUI;
1661
+ fd->dwFileAttributes = GetFileAttributes(file_name);
1662
+
1663
+ if (!GetFileTime(hFile, NULL, NULL, &fd->ftLastWriteTime))
1664
+ {
1665
+ fd->dwFlags &= ~FD_WRITESTIME;
1666
+ }
1667
+
1668
+ fd->nFileSizeLow = GetFileSize(hFile, &fd->nFileSizeHigh);
1669
+ wcscpy_s(fd->cFileName, sizeof(fd->cFileName) / 2, file_name + pathLen);
1670
+ (void)CloseHandle(hFile);
1671
+ return fd;
1672
+ }
1673
+
1674
+ static BOOL wf_cliprdr_array_ensure_capacity(wfClipboard* clipboard)
1675
+ {
1676
+ if (!clipboard)
1677
+ return FALSE;
1678
+
1679
+ if (clipboard->nFiles == clipboard->file_array_size)
1680
+ {
1681
+ size_t new_size;
1682
+ FILEDESCRIPTORW** new_fd;
1683
+ WCHAR** new_name;
1684
+ new_size = (clipboard->file_array_size + 1) * 2;
1685
+ new_fd = (FILEDESCRIPTORW**)realloc(clipboard->fileDescriptor,
1686
+ new_size * sizeof(FILEDESCRIPTORW*));
1687
+
1688
+ if (new_fd)
1689
+ clipboard->fileDescriptor = new_fd;
1690
+
1691
+ new_name = (WCHAR**)realloc(clipboard->file_names, new_size * sizeof(WCHAR*));
1692
+
1693
+ if (new_name)
1694
+ clipboard->file_names = new_name;
1695
+
1696
+ if (!new_fd || !new_name)
1697
+ return FALSE;
1698
+
1699
+ clipboard->file_array_size = new_size;
1700
+ }
1701
+
1702
+ return TRUE;
1703
+ }
1704
+
1705
+ static BOOL wf_cliprdr_add_to_file_arrays(wfClipboard* clipboard, WCHAR* full_file_name,
1706
+ size_t pathLen)
1707
+ {
1708
+ if (!wf_cliprdr_array_ensure_capacity(clipboard))
1709
+ return FALSE;
1710
+
1711
+ /* add to name array */
1712
+ clipboard->file_names[clipboard->nFiles] = (LPWSTR)malloc(MAX_PATH * 2);
1713
+
1714
+ if (!clipboard->file_names[clipboard->nFiles])
1715
+ return FALSE;
1716
+
1717
+ wcscpy_s(clipboard->file_names[clipboard->nFiles], MAX_PATH, full_file_name);
1718
+ /* add to descriptor array */
1719
+ clipboard->fileDescriptor[clipboard->nFiles] =
1720
+ wf_cliprdr_get_file_descriptor(full_file_name, pathLen);
1721
+
1722
+ if (!clipboard->fileDescriptor[clipboard->nFiles])
1723
+ {
1724
+ free(clipboard->file_names[clipboard->nFiles]);
1725
+ return FALSE;
1726
+ }
1727
+
1728
+ clipboard->nFiles++;
1729
+ return TRUE;
1730
+ }
1731
+
1732
+ static BOOL wf_cliprdr_traverse_directory(wfClipboard* clipboard, WCHAR* Dir, size_t pathLen)
1733
+ {
1734
+ HANDLE hFind;
1735
+ WCHAR DirSpec[MAX_PATH];
1736
+ WIN32_FIND_DATA FindFileData;
1737
+
1738
+ if (!clipboard || !Dir)
1739
+ return FALSE;
1740
+
1741
+ StringCchCopy(DirSpec, MAX_PATH, Dir);
1742
+ StringCchCat(DirSpec, MAX_PATH, TEXT("\\*"));
1743
+ hFind = FindFirstFile(DirSpec, &FindFileData);
1744
+
1745
+ if (hFind == INVALID_HANDLE_VALUE)
1746
+ {
1747
+ DEBUG_CLIPRDR("FindFirstFile failed with 0x%x.", GetLastError());
1748
+ return FALSE;
1749
+ }
1750
+
1751
+ while (FindNextFile(hFind, &FindFileData))
1752
+ {
1753
+ if ((((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) &&
1754
+ (wcscmp(FindFileData.cFileName, _T(".")) == 0)) ||
1755
+ (wcscmp(FindFileData.cFileName, _T("..")) == 0))
1756
+ {
1757
+ continue;
1758
+ }
1759
+
1760
+ if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
1761
+ {
1762
+ WCHAR DirAdd[MAX_PATH];
1763
+ StringCchCopy(DirAdd, MAX_PATH, Dir);
1764
+ StringCchCat(DirAdd, MAX_PATH, _T("\\"));
1765
+ StringCchCat(DirAdd, MAX_PATH, FindFileData.cFileName);
1766
+
1767
+ if (!wf_cliprdr_add_to_file_arrays(clipboard, DirAdd, pathLen))
1768
+ return FALSE;
1769
+
1770
+ if (!wf_cliprdr_traverse_directory(clipboard, DirAdd, pathLen))
1771
+ return FALSE;
1772
+ }
1773
+ else
1774
+ {
1775
+ WCHAR fileName[MAX_PATH];
1776
+ StringCchCopy(fileName, MAX_PATH, Dir);
1777
+ StringCchCat(fileName, MAX_PATH, _T("\\"));
1778
+ StringCchCat(fileName, MAX_PATH, FindFileData.cFileName);
1779
+
1780
+ if (!wf_cliprdr_add_to_file_arrays(clipboard, fileName, pathLen))
1781
+ return FALSE;
1782
+ }
1783
+ }
1784
+
1785
+ FindClose(hFind);
1786
+ return TRUE;
1787
+ }
1788
+
1789
+ static UINT wf_cliprdr_send_client_capabilities(wfClipboard* clipboard)
1790
+ {
1791
+ CLIPRDR_CAPABILITIES capabilities;
1792
+ CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet;
1793
+
1794
+ if (!clipboard || !clipboard->context || !clipboard->context->ClientCapabilities)
1795
+ return ERROR_INTERNAL_ERROR;
1796
+
1797
+ capabilities.cCapabilitiesSets = 1;
1798
+ capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*)&(generalCapabilitySet);
1799
+ generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
1800
+ generalCapabilitySet.capabilitySetLength = 12;
1801
+ generalCapabilitySet.version = CB_CAPS_VERSION_2;
1802
+ generalCapabilitySet.generalFlags =
1803
+ CB_USE_LONG_FORMAT_NAMES | CB_STREAM_FILECLIP_ENABLED | CB_FILECLIP_NO_FILE_PATHS;
1804
+ return clipboard->context->ClientCapabilities(clipboard->context, &capabilities);
1805
+ }
1806
+
1807
+ /**
1808
+ * Function description
1809
+ *
1810
+ * @return 0 on success, otherwise a Win32 error code
1811
+ */
1812
+ static UINT wf_cliprdr_monitor_ready(CliprdrClientContext* context,
1813
+ const CLIPRDR_MONITOR_READY* monitorReady)
1814
+ {
1815
+ UINT rc;
1816
+ wfClipboard* clipboard = (wfClipboard*)context->custom;
1817
+
1818
+ if (!context || !monitorReady)
1819
+ return ERROR_INTERNAL_ERROR;
1820
+
1821
+ clipboard->sync = TRUE;
1822
+ rc = wf_cliprdr_send_client_capabilities(clipboard);
1823
+
1824
+ if (rc != CHANNEL_RC_OK)
1825
+ return rc;
1826
+
1827
+ return cliprdr_send_format_list(clipboard);
1828
+ }
1829
+
1830
+ /**
1831
+ * Function description
1832
+ *
1833
+ * @return 0 on success, otherwise a Win32 error code
1834
+ */
1835
+ static UINT wf_cliprdr_server_capabilities(CliprdrClientContext* context,
1836
+ const CLIPRDR_CAPABILITIES* capabilities)
1837
+ {
1838
+ CLIPRDR_CAPABILITY_SET* capabilitySet;
1839
+ wfClipboard* clipboard = (wfClipboard*)context->custom;
1840
+
1841
+ if (!context || !capabilities)
1842
+ return ERROR_INTERNAL_ERROR;
1843
+
1844
+ for (UINT32 index = 0; index < capabilities->cCapabilitiesSets; index++)
1845
+ {
1846
+ capabilitySet = &(capabilities->capabilitySets[index]);
1847
+
1848
+ if ((capabilitySet->capabilitySetType == CB_CAPSTYPE_GENERAL) &&
1849
+ (capabilitySet->capabilitySetLength >= CB_CAPSTYPE_GENERAL_LEN))
1850
+ {
1851
+ CLIPRDR_GENERAL_CAPABILITY_SET* generalCapabilitySet =
1852
+ (CLIPRDR_GENERAL_CAPABILITY_SET*)capabilitySet;
1853
+ clipboard->capabilities = generalCapabilitySet->generalFlags;
1854
+ break;
1855
+ }
1856
+ }
1857
+
1858
+ return CHANNEL_RC_OK;
1859
+ }
1860
+
1861
+ /**
1862
+ * Function description
1863
+ *
1864
+ * @return 0 on success, otherwise a Win32 error code
1865
+ */
1866
+ static UINT wf_cliprdr_server_format_list(CliprdrClientContext* context,
1867
+ const CLIPRDR_FORMAT_LIST* formatList)
1868
+ {
1869
+ UINT rc = ERROR_INTERNAL_ERROR;
1870
+ formatMapping* mapping;
1871
+ CLIPRDR_FORMAT* format;
1872
+ wfClipboard* clipboard = (wfClipboard*)context->custom;
1873
+
1874
+ if (!clear_format_map(clipboard))
1875
+ return ERROR_INTERNAL_ERROR;
1876
+
1877
+ for (UINT32 i = 0; i < formatList->numFormats; i++)
1878
+ {
1879
+ format = &(formatList->formats[i]);
1880
+ mapping = &(clipboard->format_mappings[i]);
1881
+ mapping->remote_format_id = format->formatId;
1882
+
1883
+ if (format->formatName)
1884
+ {
1885
+ mapping->name = ConvertUtf8ToWCharAlloc(format->formatName, NULL);
1886
+
1887
+ if (mapping->name)
1888
+ mapping->local_format_id = RegisterClipboardFormatW((LPWSTR)mapping->name);
1889
+ }
1890
+ else
1891
+ {
1892
+ mapping->name = NULL;
1893
+ mapping->local_format_id = mapping->remote_format_id;
1894
+ }
1895
+
1896
+ clipboard->map_size++;
1897
+ map_ensure_capacity(clipboard);
1898
+ }
1899
+
1900
+ if (file_transferring(clipboard))
1901
+ {
1902
+ if (PostMessage(clipboard->hwnd, WM_CLIPRDR_MESSAGE, OLE_SETCLIPBOARD, 0))
1903
+ rc = CHANNEL_RC_OK;
1904
+ }
1905
+ else
1906
+ {
1907
+ if (!try_open_clipboard(clipboard->hwnd))
1908
+ return CHANNEL_RC_OK; /* Ignore, other app holding clipboard */
1909
+
1910
+ if (EmptyClipboard())
1911
+ {
1912
+ for (UINT32 i = 0; i < (UINT32)clipboard->map_size; i++)
1913
+ SetClipboardData(clipboard->format_mappings[i].local_format_id, NULL);
1914
+
1915
+ rc = CHANNEL_RC_OK;
1916
+ }
1917
+
1918
+ if (!CloseClipboard() && GetLastError())
1919
+ return ERROR_INTERNAL_ERROR;
1920
+ }
1921
+
1922
+ return rc;
1923
+ }
1924
+
1925
+ /**
1926
+ * Function description
1927
+ *
1928
+ * @return 0 on success, otherwise a Win32 error code
1929
+ */
1930
+ static UINT
1931
+ wf_cliprdr_server_format_list_response(CliprdrClientContext* context,
1932
+ const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
1933
+ {
1934
+ (void)context;
1935
+ (void)formatListResponse;
1936
+
1937
+ if (formatListResponse->common.msgFlags != CB_RESPONSE_OK)
1938
+ WLog_WARN(TAG, "format list update failed");
1939
+
1940
+ return CHANNEL_RC_OK;
1941
+ }
1942
+
1943
+ /**
1944
+ * Function description
1945
+ *
1946
+ * @return 0 on success, otherwise a Win32 error code
1947
+ */
1948
+ static UINT
1949
+ wf_cliprdr_server_lock_clipboard_data(CliprdrClientContext* context,
1950
+ const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
1951
+ {
1952
+ (void)context;
1953
+ (void)lockClipboardData;
1954
+ return CHANNEL_RC_OK;
1955
+ }
1956
+
1957
+ /**
1958
+ * Function description
1959
+ *
1960
+ * @return 0 on success, otherwise a Win32 error code
1961
+ */
1962
+ static UINT
1963
+ wf_cliprdr_server_unlock_clipboard_data(CliprdrClientContext* context,
1964
+ const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
1965
+ {
1966
+ (void)context;
1967
+ (void)unlockClipboardData;
1968
+ return CHANNEL_RC_OK;
1969
+ }
1970
+
1971
+ static BOOL wf_cliprdr_process_filename(wfClipboard* clipboard, WCHAR* wFileName, size_t str_len)
1972
+ {
1973
+ size_t pathLen;
1974
+ size_t offset = str_len;
1975
+
1976
+ if (!clipboard || !wFileName)
1977
+ return FALSE;
1978
+
1979
+ /* find the last '\' in full file name */
1980
+ while (offset > 0)
1981
+ {
1982
+ if (wFileName[offset] == L'\\')
1983
+ break;
1984
+ else
1985
+ offset--;
1986
+ }
1987
+
1988
+ pathLen = offset + 1;
1989
+
1990
+ if (!wf_cliprdr_add_to_file_arrays(clipboard, wFileName, pathLen))
1991
+ return FALSE;
1992
+
1993
+ if ((clipboard->fileDescriptor[clipboard->nFiles - 1]->dwFileAttributes &
1994
+ FILE_ATTRIBUTE_DIRECTORY) != 0)
1995
+ {
1996
+ /* this is a directory */
1997
+ if (!wf_cliprdr_traverse_directory(clipboard, wFileName, pathLen))
1998
+ return FALSE;
1999
+ }
2000
+
2001
+ return TRUE;
2002
+ }
2003
+
2004
+ static SSIZE_T wf_cliprdr_tryopen(wfClipboard* clipboard, UINT32 requestedFormatId, BYTE** pData)
2005
+ {
2006
+ SSIZE_T rc = -1;
2007
+ WINPR_ASSERT(clipboard);
2008
+ WINPR_ASSERT(pData);
2009
+
2010
+ *pData = NULL;
2011
+
2012
+ /* Ignore if other app is holding the clipboard */
2013
+ if (!try_open_clipboard(clipboard->hwnd))
2014
+ return 0;
2015
+
2016
+ HANDLE hClipdata = GetClipboardData(requestedFormatId);
2017
+
2018
+ if (!hClipdata)
2019
+ goto fail;
2020
+
2021
+ char* globlemem = (char*)GlobalLock(hClipdata);
2022
+ const SSIZE_T size = GlobalSize(hClipdata);
2023
+ if (size <= 0)
2024
+ goto unlock;
2025
+
2026
+ BYTE* buff = malloc(size);
2027
+ if (buff == NULL)
2028
+ goto fail;
2029
+ CopyMemory(buff, globlemem, size);
2030
+ *pData = buff;
2031
+ rc = size;
2032
+
2033
+ unlock:
2034
+ GlobalUnlock(hClipdata);
2035
+
2036
+ fail:
2037
+ CloseClipboard();
2038
+
2039
+ return rc;
2040
+ }
2041
+
2042
+ static SSIZE_T wf_cliprdr_get_filedescriptor(wfClipboard* clipboard, BYTE** pData)
2043
+ {
2044
+ WINPR_ASSERT(clipboard);
2045
+ WINPR_ASSERT(pData);
2046
+
2047
+ SSIZE_T rc = -1;
2048
+ LPDATAOBJECT dataObj = NULL;
2049
+ FORMATETC format_etc = { 0 };
2050
+ STGMEDIUM stg_medium = { 0 };
2051
+
2052
+ *pData = NULL;
2053
+
2054
+ HRESULT result = OleGetClipboard(&dataObj);
2055
+ if (FAILED(result))
2056
+ return -1;
2057
+
2058
+ /* get DROPFILES struct from OLE */
2059
+ format_etc.cfFormat = CF_HDROP;
2060
+ format_etc.tymed = TYMED_HGLOBAL;
2061
+ format_etc.dwAspect = 1;
2062
+ format_etc.lindex = -1;
2063
+ result = IDataObject_GetData(dataObj, &format_etc, &stg_medium);
2064
+
2065
+ if (FAILED(result))
2066
+ {
2067
+ DEBUG_CLIPRDR("dataObj->GetData failed.");
2068
+ goto exit;
2069
+ }
2070
+
2071
+ HGLOBAL hdl = stg_medium.u.hGlobal;
2072
+ DROPFILES* dropFiles = (DROPFILES*)GlobalLock(hdl);
2073
+
2074
+ if (!dropFiles)
2075
+ {
2076
+ ReleaseStgMedium(&stg_medium);
2077
+ clipboard->nFiles = 0;
2078
+ goto exit;
2079
+ }
2080
+
2081
+ clear_file_array(clipboard);
2082
+
2083
+ if (dropFiles->fWide)
2084
+ {
2085
+ /* dropFiles contains file names */
2086
+ size_t len = 0;
2087
+ for (WCHAR* wFileName = (WCHAR*)((char*)dropFiles + dropFiles->pFiles);
2088
+ (len = wcslen(wFileName)) > 0; wFileName += len + 1)
2089
+ {
2090
+ wf_cliprdr_process_filename(clipboard, wFileName, wcslen(wFileName));
2091
+ }
2092
+ }
2093
+ else
2094
+ {
2095
+ size_t len = 0;
2096
+ for (char* p = (char*)((char*)dropFiles + dropFiles->pFiles); (len = strlen(p)) > 0;
2097
+ p += len + 1, clipboard->nFiles++)
2098
+ {
2099
+ const int cchWideChar = MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, NULL, 0);
2100
+ WCHAR* wFileName = (LPWSTR)calloc(cchWideChar, sizeof(WCHAR));
2101
+ MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, wFileName, cchWideChar);
2102
+ wf_cliprdr_process_filename(clipboard, wFileName, cchWideChar);
2103
+ free(wFileName);
2104
+ }
2105
+ }
2106
+
2107
+ GlobalUnlock(hdl);
2108
+ ReleaseStgMedium(&stg_medium);
2109
+ exit:
2110
+ {
2111
+ const size_t size = 4ull + clipboard->nFiles * sizeof(FILEDESCRIPTORW);
2112
+ FILEGROUPDESCRIPTORW* groupDsc = (FILEGROUPDESCRIPTORW*)calloc(size, 1);
2113
+
2114
+ if (groupDsc)
2115
+ {
2116
+ groupDsc->cItems = clipboard->nFiles;
2117
+
2118
+ for (size_t i = 0; i < clipboard->nFiles; i++)
2119
+ {
2120
+ if (clipboard->fileDescriptor[i])
2121
+ groupDsc->fgd[i] = *clipboard->fileDescriptor[i];
2122
+ }
2123
+
2124
+ *pData = (BYTE*)groupDsc;
2125
+ rc = size;
2126
+ }
2127
+ }
2128
+
2129
+ IDataObject_Release(dataObj);
2130
+ return rc;
2131
+ }
2132
+
2133
+ /**
2134
+ * Function description
2135
+ *
2136
+ * @return 0 on success, otherwise a Win32 error code
2137
+ */
2138
+ static UINT
2139
+ wf_cliprdr_server_format_data_request(CliprdrClientContext* context,
2140
+ const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
2141
+ {
2142
+ CLIPRDR_FORMAT_DATA_RESPONSE response = { 0 };
2143
+
2144
+ if (!context || !formatDataRequest)
2145
+ return ERROR_INTERNAL_ERROR;
2146
+
2147
+ wfClipboard* clipboard = (wfClipboard*)context->custom;
2148
+
2149
+ if (!clipboard)
2150
+ return ERROR_INTERNAL_ERROR;
2151
+
2152
+ const UINT32 requestedFormatId = formatDataRequest->requestedFormatId;
2153
+
2154
+ if (requestedFormatId == RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW))
2155
+ {
2156
+ const SSIZE_T res = wf_cliprdr_get_filedescriptor(clipboard, &response.requestedFormatData);
2157
+ if (res > 0)
2158
+ response.common.dataLen = (UINT32)res;
2159
+ }
2160
+ else
2161
+ {
2162
+ const SSIZE_T res =
2163
+ wf_cliprdr_tryopen(clipboard, requestedFormatId, &response.requestedFormatData);
2164
+ if (res > 0)
2165
+ response.common.dataLen = (UINT32)res;
2166
+ }
2167
+
2168
+ response.common.msgFlags = CB_RESPONSE_OK;
2169
+
2170
+ const UINT rc = clipboard->context->ClientFormatDataResponse(clipboard->context, &response);
2171
+ free(response.requestedFormatData);
2172
+ return rc;
2173
+ }
2174
+
2175
+ /**
2176
+ * Function description
2177
+ *
2178
+ * @return 0 on success, otherwise a Win32 error code
2179
+ */
2180
+ static UINT
2181
+ wf_cliprdr_server_format_data_response(CliprdrClientContext* context,
2182
+ const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
2183
+ {
2184
+ BYTE* data;
2185
+ HANDLE hMem;
2186
+ wfClipboard* clipboard;
2187
+
2188
+ if (!context || !formatDataResponse)
2189
+ return ERROR_INTERNAL_ERROR;
2190
+
2191
+ clipboard = (wfClipboard*)context->custom;
2192
+
2193
+ if (!clipboard)
2194
+ return ERROR_INTERNAL_ERROR;
2195
+
2196
+ if (formatDataResponse->common.msgFlags != CB_RESPONSE_OK)
2197
+ {
2198
+ clipboard->hmem = NULL;
2199
+
2200
+ if (!SetEvent(clipboard->response_data_event))
2201
+ return ERROR_INTERNAL_ERROR;
2202
+
2203
+ return CHANNEL_RC_OK;
2204
+ }
2205
+
2206
+ hMem = GlobalAlloc(GMEM_MOVEABLE, formatDataResponse->common.dataLen);
2207
+
2208
+ if (!hMem)
2209
+ return ERROR_INTERNAL_ERROR;
2210
+
2211
+ data = (BYTE*)GlobalLock(hMem);
2212
+
2213
+ if (!data)
2214
+ {
2215
+ GlobalFree(hMem);
2216
+ return ERROR_INTERNAL_ERROR;
2217
+ }
2218
+
2219
+ CopyMemory(data, formatDataResponse->requestedFormatData, formatDataResponse->common.dataLen);
2220
+
2221
+ if (!GlobalUnlock(hMem) && GetLastError())
2222
+ {
2223
+ GlobalFree(hMem);
2224
+ return ERROR_INTERNAL_ERROR;
2225
+ }
2226
+
2227
+ clipboard->hmem = hMem;
2228
+
2229
+ if (!SetEvent(clipboard->response_data_event))
2230
+ return ERROR_INTERNAL_ERROR;
2231
+
2232
+ return CHANNEL_RC_OK;
2233
+ }
2234
+
2235
+ /**
2236
+ * Function description
2237
+ *
2238
+ * @return 0 on success, otherwise a Win32 error code
2239
+ */
2240
+ static UINT
2241
+ wf_cliprdr_server_file_contents_request(CliprdrClientContext* context,
2242
+ const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
2243
+ {
2244
+ DWORD uSize = 0;
2245
+ BYTE* pData = NULL;
2246
+ HRESULT hRet = S_OK;
2247
+ FORMATETC vFormatEtc = { 0 };
2248
+ LPDATAOBJECT pDataObj = NULL;
2249
+ STGMEDIUM vStgMedium = { 0 };
2250
+ BOOL bIsStreamFile = TRUE;
2251
+ static LPSTREAM pStreamStc = NULL;
2252
+ static UINT32 uStreamIdStc = 0;
2253
+ wfClipboard* clipboard;
2254
+ UINT rc = ERROR_INTERNAL_ERROR;
2255
+ UINT sRc;
2256
+ UINT32 cbRequested;
2257
+
2258
+ if (!context || !fileContentsRequest)
2259
+ return ERROR_INTERNAL_ERROR;
2260
+
2261
+ clipboard = (wfClipboard*)context->custom;
2262
+
2263
+ if (!clipboard)
2264
+ return ERROR_INTERNAL_ERROR;
2265
+
2266
+ cbRequested = fileContentsRequest->cbRequested;
2267
+ if (fileContentsRequest->dwFlags == FILECONTENTS_SIZE)
2268
+ cbRequested = sizeof(UINT64);
2269
+
2270
+ pData = (BYTE*)calloc(1, cbRequested);
2271
+
2272
+ if (!pData)
2273
+ goto error;
2274
+
2275
+ hRet = OleGetClipboard(&pDataObj);
2276
+
2277
+ if (FAILED(hRet))
2278
+ {
2279
+ WLog_ERR(TAG, "filecontents: get ole clipboard failed.");
2280
+ goto error;
2281
+ }
2282
+
2283
+ vFormatEtc.cfFormat = RegisterClipboardFormat(CFSTR_FILECONTENTS);
2284
+ vFormatEtc.tymed = TYMED_ISTREAM;
2285
+ vFormatEtc.dwAspect = 1;
2286
+ vFormatEtc.lindex = fileContentsRequest->listIndex;
2287
+ vFormatEtc.ptd = NULL;
2288
+
2289
+ if ((uStreamIdStc != fileContentsRequest->streamId) || !pStreamStc)
2290
+ {
2291
+ LPENUMFORMATETC pEnumFormatEtc;
2292
+ ULONG CeltFetched;
2293
+ FORMATETC vFormatEtc2;
2294
+
2295
+ if (pStreamStc)
2296
+ {
2297
+ IStream_Release(pStreamStc);
2298
+ pStreamStc = NULL;
2299
+ }
2300
+
2301
+ bIsStreamFile = FALSE;
2302
+ hRet = IDataObject_EnumFormatEtc(pDataObj, DATADIR_GET, &pEnumFormatEtc);
2303
+
2304
+ if (hRet == S_OK)
2305
+ {
2306
+ do
2307
+ {
2308
+ hRet = IEnumFORMATETC_Next(pEnumFormatEtc, 1, &vFormatEtc2, &CeltFetched);
2309
+
2310
+ if (hRet == S_OK)
2311
+ {
2312
+ if (vFormatEtc2.cfFormat == RegisterClipboardFormat(CFSTR_FILECONTENTS))
2313
+ {
2314
+ hRet = IDataObject_GetData(pDataObj, &vFormatEtc, &vStgMedium);
2315
+
2316
+ if (hRet == S_OK)
2317
+ {
2318
+ pStreamStc = vStgMedium.u.pstm;
2319
+ uStreamIdStc = fileContentsRequest->streamId;
2320
+ bIsStreamFile = TRUE;
2321
+ }
2322
+
2323
+ break;
2324
+ }
2325
+ }
2326
+ } while (hRet == S_OK);
2327
+ }
2328
+ }
2329
+
2330
+ if (bIsStreamFile == TRUE)
2331
+ {
2332
+ if (fileContentsRequest->dwFlags == FILECONTENTS_SIZE)
2333
+ {
2334
+ STATSTG vStatStg = { 0 };
2335
+ hRet = IStream_Stat(pStreamStc, &vStatStg, STATFLAG_NONAME);
2336
+
2337
+ if (hRet == S_OK)
2338
+ {
2339
+ *((UINT32*)&pData[0]) = vStatStg.cbSize.QuadPart & 0xFFFFFFFF;
2340
+ *((UINT32*)&pData[4]) = (vStatStg.cbSize.QuadPart >> 32) & 0xFFFFFFFF;
2341
+ uSize = cbRequested;
2342
+ }
2343
+ }
2344
+ else if (fileContentsRequest->dwFlags == FILECONTENTS_RANGE)
2345
+ {
2346
+ LARGE_INTEGER dlibMove;
2347
+ ULARGE_INTEGER dlibNewPosition;
2348
+ dlibMove.QuadPart = (INT64)(((UINT64)fileContentsRequest->nPositionHigh << 32) |
2349
+ fileContentsRequest->nPositionLow);
2350
+ hRet = IStream_Seek(pStreamStc, dlibMove, STREAM_SEEK_SET, &dlibNewPosition);
2351
+
2352
+ if (SUCCEEDED(hRet))
2353
+ hRet = IStream_Read(pStreamStc, pData, cbRequested, (PULONG)&uSize);
2354
+ }
2355
+ }
2356
+ else
2357
+ {
2358
+ if (fileContentsRequest->dwFlags == FILECONTENTS_SIZE)
2359
+ {
2360
+ if (clipboard->nFiles <= fileContentsRequest->listIndex)
2361
+ goto error;
2362
+ *((UINT32*)&pData[0]) =
2363
+ clipboard->fileDescriptor[fileContentsRequest->listIndex]->nFileSizeLow;
2364
+ *((UINT32*)&pData[4]) =
2365
+ clipboard->fileDescriptor[fileContentsRequest->listIndex]->nFileSizeHigh;
2366
+ uSize = cbRequested;
2367
+ }
2368
+ else if (fileContentsRequest->dwFlags == FILECONTENTS_RANGE)
2369
+ {
2370
+ BOOL bRet;
2371
+ if (clipboard->nFiles <= fileContentsRequest->listIndex)
2372
+ goto error;
2373
+ bRet = wf_cliprdr_get_file_contents(
2374
+ clipboard->file_names[fileContentsRequest->listIndex], pData,
2375
+ fileContentsRequest->nPositionLow, fileContentsRequest->nPositionHigh, cbRequested,
2376
+ &uSize);
2377
+
2378
+ if (bRet == FALSE)
2379
+ {
2380
+ WLog_ERR(TAG, "get file contents failed.");
2381
+ uSize = 0;
2382
+ goto error;
2383
+ }
2384
+ }
2385
+ }
2386
+
2387
+ rc = CHANNEL_RC_OK;
2388
+ error:
2389
+
2390
+ if (pDataObj)
2391
+ IDataObject_Release(pDataObj);
2392
+
2393
+ if (uSize == 0)
2394
+ {
2395
+ free(pData);
2396
+ pData = NULL;
2397
+ }
2398
+
2399
+ sRc =
2400
+ cliprdr_send_response_filecontents(clipboard, fileContentsRequest->streamId, uSize, pData);
2401
+ free(pData);
2402
+
2403
+ if (sRc != CHANNEL_RC_OK)
2404
+ return sRc;
2405
+
2406
+ return rc;
2407
+ }
2408
+
2409
+ /**
2410
+ * Function description
2411
+ *
2412
+ * @return 0 on success, otherwise a Win32 error code
2413
+ */
2414
+ static UINT
2415
+ wf_cliprdr_server_file_contents_response(CliprdrClientContext* context,
2416
+ const CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse)
2417
+ {
2418
+ wfClipboard* clipboard;
2419
+
2420
+ if (!context || !fileContentsResponse)
2421
+ return ERROR_INTERNAL_ERROR;
2422
+
2423
+ if (fileContentsResponse->common.msgFlags != CB_RESPONSE_OK)
2424
+ return E_FAIL;
2425
+
2426
+ clipboard = (wfClipboard*)context->custom;
2427
+
2428
+ if (!clipboard)
2429
+ return ERROR_INTERNAL_ERROR;
2430
+
2431
+ clipboard->req_fsize = fileContentsResponse->cbRequested;
2432
+ clipboard->req_fdata = (char*)malloc(fileContentsResponse->cbRequested);
2433
+
2434
+ if (!clipboard->req_fdata)
2435
+ return ERROR_INTERNAL_ERROR;
2436
+
2437
+ CopyMemory(clipboard->req_fdata, fileContentsResponse->requestedData,
2438
+ fileContentsResponse->cbRequested);
2439
+
2440
+ if (!SetEvent(clipboard->req_fevent))
2441
+ {
2442
+ free(clipboard->req_fdata);
2443
+ return ERROR_INTERNAL_ERROR;
2444
+ }
2445
+
2446
+ return CHANNEL_RC_OK;
2447
+ }
2448
+
2449
+ BOOL wf_cliprdr_init(wfContext* wfc, CliprdrClientContext* cliprdr)
2450
+ {
2451
+ wfClipboard* clipboard;
2452
+ rdpContext* context = (rdpContext*)wfc;
2453
+
2454
+ if (!context || !cliprdr)
2455
+ return FALSE;
2456
+
2457
+ wfc->clipboard = (wfClipboard*)calloc(1, sizeof(wfClipboard));
2458
+
2459
+ if (!wfc->clipboard)
2460
+ return FALSE;
2461
+
2462
+ clipboard = wfc->clipboard;
2463
+ clipboard->wfc = wfc;
2464
+ clipboard->context = cliprdr;
2465
+ clipboard->channels = context->channels;
2466
+ clipboard->sync = FALSE;
2467
+ clipboard->map_capacity = 32;
2468
+ clipboard->map_size = 0;
2469
+ clipboard->hUser32 = LoadLibraryA("user32.dll");
2470
+
2471
+ if (clipboard->hUser32)
2472
+ {
2473
+ clipboard->AddClipboardFormatListener = GetProcAddressAs(
2474
+ clipboard->hUser32, "AddClipboardFormatListener", fnAddClipboardFormatListener);
2475
+ clipboard->RemoveClipboardFormatListener = GetProcAddressAs(
2476
+ clipboard->hUser32, "RemoveClipboardFormatListener", fnRemoveClipboardFormatListener);
2477
+ clipboard->GetUpdatedClipboardFormats = GetProcAddressAs(
2478
+ clipboard->hUser32, "GetUpdatedClipboardFormats", fnGetUpdatedClipboardFormats);
2479
+ }
2480
+
2481
+ if (!(clipboard->hUser32 && clipboard->AddClipboardFormatListener &&
2482
+ clipboard->RemoveClipboardFormatListener && clipboard->GetUpdatedClipboardFormats))
2483
+ clipboard->legacyApi = TRUE;
2484
+
2485
+ if (!(clipboard->format_mappings =
2486
+ (formatMapping*)calloc(clipboard->map_capacity, sizeof(formatMapping))))
2487
+ goto error;
2488
+
2489
+ if (!(clipboard->response_data_event = CreateEvent(NULL, TRUE, FALSE, NULL)))
2490
+ goto error;
2491
+
2492
+ if (!(clipboard->req_fevent = CreateEvent(NULL, TRUE, FALSE, NULL)))
2493
+ goto error;
2494
+
2495
+ if (!(clipboard->thread = CreateThread(NULL, 0, cliprdr_thread_func, clipboard, 0, NULL)))
2496
+ goto error;
2497
+
2498
+ cliprdr->MonitorReady = wf_cliprdr_monitor_ready;
2499
+ cliprdr->ServerCapabilities = wf_cliprdr_server_capabilities;
2500
+ cliprdr->ServerFormatList = wf_cliprdr_server_format_list;
2501
+ cliprdr->ServerFormatListResponse = wf_cliprdr_server_format_list_response;
2502
+ cliprdr->ServerLockClipboardData = wf_cliprdr_server_lock_clipboard_data;
2503
+ cliprdr->ServerUnlockClipboardData = wf_cliprdr_server_unlock_clipboard_data;
2504
+ cliprdr->ServerFormatDataRequest = wf_cliprdr_server_format_data_request;
2505
+ cliprdr->ServerFormatDataResponse = wf_cliprdr_server_format_data_response;
2506
+ cliprdr->ServerFileContentsRequest = wf_cliprdr_server_file_contents_request;
2507
+ cliprdr->ServerFileContentsResponse = wf_cliprdr_server_file_contents_response;
2508
+ cliprdr->custom = (void*)wfc->clipboard;
2509
+ return TRUE;
2510
+ error:
2511
+ wf_cliprdr_uninit(wfc, cliprdr);
2512
+ return FALSE;
2513
+ }
2514
+
2515
+ BOOL wf_cliprdr_uninit(wfContext* wfc, CliprdrClientContext* cliprdr)
2516
+ {
2517
+ wfClipboard* clipboard;
2518
+
2519
+ if (!wfc || !cliprdr)
2520
+ return FALSE;
2521
+
2522
+ clipboard = wfc->clipboard;
2523
+
2524
+ if (!clipboard)
2525
+ return FALSE;
2526
+
2527
+ cliprdr->custom = NULL;
2528
+
2529
+ if (clipboard->hwnd)
2530
+ PostMessage(clipboard->hwnd, WM_QUIT, 0, 0);
2531
+
2532
+ if (clipboard->thread)
2533
+ {
2534
+ (void)WaitForSingleObject(clipboard->thread, INFINITE);
2535
+ (void)CloseHandle(clipboard->thread);
2536
+ }
2537
+
2538
+ if (clipboard->response_data_event)
2539
+ (void)CloseHandle(clipboard->response_data_event);
2540
+
2541
+ if (clipboard->req_fevent)
2542
+ (void)CloseHandle(clipboard->req_fevent);
2543
+
2544
+ clear_file_array(clipboard);
2545
+ clear_format_map(clipboard);
2546
+ free(clipboard->format_mappings);
2547
+ free(clipboard);
2548
+ return TRUE;
2549
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_cliprdr.h ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Windows Clipboard Redirection
4
+ *
5
+ * Copyright 2012 Jason Champion
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ #ifndef FREERDP_CLIENT_WIN_CLIPRDR_H
20
+ #define FREERDP_CLIENT_WIN_CLIPRDR_H
21
+
22
+ #include "wf_client.h"
23
+
24
+ BOOL wf_cliprdr_init(wfContext* wfc, CliprdrClientContext* cliprdr);
25
+ BOOL wf_cliprdr_uninit(wfContext* wfc, CliprdrClientContext* cliprdr);
26
+
27
+ #endif /* FREERDP_CLIENT_WIN_CLIPRDR_H */
local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_floatbar.c ADDED
@@ -0,0 +1,730 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Windows Float Bar
4
+ *
5
+ * Copyright 2013 Zhang Zhaolong <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #include <winpr/crt.h>
21
+ #include <winpr/windows.h>
22
+
23
+ #include "wf_client.h"
24
+ #include "wf_floatbar.h"
25
+
26
+ #include "resource/resource.h"
27
+ #include "wf_gdi.h"
28
+ #ifdef _MSC_VER
29
+ #pragma comment(lib, "Msimg32.lib")
30
+ #endif
31
+
32
+ #define TAG CLIENT_TAG("windows.floatbar")
33
+
34
+ /* TIMERs */
35
+ #define TIMER_HIDE 1
36
+ #define TIMER_ANIMAT_SHOW 2
37
+ #define TIMER_ANIMAT_HIDE 3
38
+
39
+ /* Button Type */
40
+ #define BUTTON_LOCKPIN 0
41
+ #define BUTTON_MINIMIZE 1
42
+ #define BUTTON_RESTORE 2
43
+ #define BUTTON_CLOSE 3
44
+ #define BTN_MAX 4
45
+
46
+ /* bmp size */
47
+ #define BACKGROUND_W 576
48
+ #define BACKGROUND_H 27
49
+ #define BUTTON_OFFSET 5
50
+ #define BUTTON_Y 2
51
+ #define BUTTON_WIDTH 23
52
+ #define BUTTON_HEIGHT 21
53
+ #define BUTTON_SPACING 1
54
+
55
+ #define LOCK_X (BACKGROUND_H + BUTTON_OFFSET)
56
+ #define CLOSE_X ((BACKGROUND_W - (BACKGROUND_H + BUTTON_OFFSET)) - BUTTON_WIDTH)
57
+ #define RESTORE_X (CLOSE_X - (BUTTON_WIDTH + BUTTON_SPACING))
58
+ #define MINIMIZE_X (RESTORE_X - (BUTTON_WIDTH + BUTTON_SPACING))
59
+ #define TEXT_X (BACKGROUND_H + ((BUTTON_WIDTH + BUTTON_SPACING) * 3) + 5)
60
+
61
+ typedef struct
62
+ {
63
+ wfFloatBar* floatbar;
64
+ int type;
65
+ int x, y, h, w;
66
+ int active;
67
+ HBITMAP bmp;
68
+ HBITMAP bmp_act;
69
+
70
+ /* Lock Specified */
71
+ HBITMAP locked_bmp;
72
+ HBITMAP locked_bmp_act;
73
+ HBITMAP unlocked_bmp;
74
+ HBITMAP unlocked_bmp_act;
75
+ } Button;
76
+
77
+ struct s_FloatBar
78
+ {
79
+ HINSTANCE root_window;
80
+ DWORD flags;
81
+ HWND parent;
82
+ HWND hwnd;
83
+ RECT rect;
84
+ LONG width;
85
+ LONG height;
86
+ LONG offset;
87
+ wfContext* wfc;
88
+ Button* buttons[BTN_MAX];
89
+ BOOL shown;
90
+ BOOL locked;
91
+ HDC hdcmem;
92
+ RECT textRect;
93
+ UINT_PTR animating;
94
+ };
95
+
96
+ static BOOL floatbar_kill_timers(wfFloatBar* floatbar)
97
+ {
98
+ UINT_PTR timers[] = { TIMER_HIDE, TIMER_ANIMAT_HIDE, TIMER_ANIMAT_SHOW };
99
+
100
+ if (!floatbar)
101
+ return FALSE;
102
+
103
+ for (size_t x = 0; x < ARRAYSIZE(timers); x++)
104
+ KillTimer(floatbar->hwnd, timers[x]);
105
+
106
+ floatbar->animating = 0;
107
+ return TRUE;
108
+ }
109
+
110
+ static BOOL floatbar_animation(wfFloatBar* const floatbar, const BOOL show)
111
+ {
112
+ UINT_PTR timer = show ? TIMER_ANIMAT_SHOW : TIMER_ANIMAT_HIDE;
113
+
114
+ if (!floatbar)
115
+ return FALSE;
116
+
117
+ if (floatbar->shown == show)
118
+ return TRUE;
119
+
120
+ if (floatbar->animating == timer)
121
+ return TRUE;
122
+
123
+ floatbar->animating = timer;
124
+
125
+ if (SetTimer(floatbar->hwnd, timer, USER_TIMER_MINIMUM, NULL) == 0)
126
+ {
127
+ DWORD err = GetLastError();
128
+ WLog_ERR(TAG, "SetTimer failed with %08" PRIx32, err);
129
+ return FALSE;
130
+ }
131
+
132
+ return TRUE;
133
+ }
134
+
135
+ static BOOL floatbar_trigger_hide(wfFloatBar* floatbar)
136
+ {
137
+ if (!floatbar_kill_timers(floatbar))
138
+ return FALSE;
139
+
140
+ if (!floatbar->locked && floatbar->shown)
141
+ {
142
+ if (SetTimer(floatbar->hwnd, TIMER_HIDE, 3000, NULL) == 0)
143
+ {
144
+ DWORD err = GetLastError();
145
+ WLog_ERR(TAG, "SetTimer failed with %08" PRIx32, err);
146
+ return FALSE;
147
+ }
148
+ }
149
+
150
+ return TRUE;
151
+ }
152
+
153
+ static BOOL floatbar_hide(wfFloatBar* floatbar)
154
+ {
155
+ if (!floatbar_kill_timers(floatbar))
156
+ return FALSE;
157
+
158
+ floatbar->offset = floatbar->height - 2;
159
+
160
+ if (!MoveWindow(floatbar->hwnd, floatbar->rect.left, -floatbar->offset, floatbar->width,
161
+ floatbar->height, TRUE))
162
+ {
163
+ DWORD err = GetLastError();
164
+ WLog_ERR(TAG, "MoveWindow failed with %08" PRIx32, err);
165
+ return FALSE;
166
+ }
167
+
168
+ floatbar->shown = FALSE;
169
+
170
+ if (!floatbar_trigger_hide(floatbar))
171
+ return FALSE;
172
+
173
+ return TRUE;
174
+ }
175
+
176
+ static BOOL floatbar_show(wfFloatBar* floatbar)
177
+ {
178
+ if (!floatbar_kill_timers(floatbar))
179
+ return FALSE;
180
+
181
+ floatbar->offset = 0;
182
+
183
+ if (!MoveWindow(floatbar->hwnd, floatbar->rect.left, -floatbar->offset, floatbar->width,
184
+ floatbar->height, TRUE))
185
+ {
186
+ DWORD err = GetLastError();
187
+ WLog_ERR(TAG, "MoveWindow failed with %08" PRIx32, err);
188
+ return FALSE;
189
+ }
190
+
191
+ floatbar->shown = TRUE;
192
+
193
+ if (!floatbar_trigger_hide(floatbar))
194
+ return FALSE;
195
+
196
+ return TRUE;
197
+ }
198
+
199
+ static BOOL button_set_locked(Button* button, BOOL locked)
200
+ {
201
+ if (locked)
202
+ {
203
+ button->bmp = button->locked_bmp;
204
+ button->bmp_act = button->locked_bmp_act;
205
+ }
206
+ else
207
+ {
208
+ button->bmp = button->unlocked_bmp;
209
+ button->bmp_act = button->unlocked_bmp_act;
210
+ }
211
+
212
+ InvalidateRect(button->floatbar->hwnd, NULL, FALSE);
213
+ UpdateWindow(button->floatbar->hwnd);
214
+ return TRUE;
215
+ }
216
+
217
+ static BOOL update_locked_state(wfFloatBar* floatbar)
218
+ {
219
+ Button* button;
220
+
221
+ if (!floatbar)
222
+ return FALSE;
223
+
224
+ button = floatbar->buttons[3];
225
+
226
+ if (!button_set_locked(button, floatbar->locked))
227
+ return FALSE;
228
+
229
+ return TRUE;
230
+ }
231
+
232
+ static int button_hit(Button* const button)
233
+ {
234
+ wfFloatBar* const floatbar = button->floatbar;
235
+
236
+ switch (button->type)
237
+ {
238
+ case BUTTON_LOCKPIN:
239
+ floatbar->locked = !floatbar->locked;
240
+ update_locked_state(floatbar);
241
+ break;
242
+
243
+ case BUTTON_MINIMIZE:
244
+ ShowWindow(floatbar->parent, SW_MINIMIZE);
245
+ break;
246
+
247
+ case BUTTON_RESTORE:
248
+ wf_toggle_fullscreen(floatbar->wfc);
249
+ break;
250
+
251
+ case BUTTON_CLOSE:
252
+ SendMessage(floatbar->parent, WM_DESTROY, 0, 0);
253
+ break;
254
+
255
+ default:
256
+ return 0;
257
+ }
258
+
259
+ return 0;
260
+ }
261
+
262
+ static int button_paint(const Button* const button, const HDC hdc)
263
+ {
264
+ if (button != NULL)
265
+ {
266
+ wfFloatBar* floatbar = button->floatbar;
267
+ BLENDFUNCTION bf;
268
+ SelectObject(floatbar->hdcmem, button->active ? button->bmp_act : button->bmp);
269
+ bf.BlendOp = AC_SRC_OVER;
270
+ bf.BlendFlags = 0;
271
+ bf.SourceConstantAlpha = 255;
272
+ bf.AlphaFormat = AC_SRC_ALPHA;
273
+ AlphaBlend(hdc, button->x, button->y, button->w, button->h, floatbar->hdcmem, 0, 0,
274
+ button->w, button->h, bf);
275
+ }
276
+
277
+ return 0;
278
+ }
279
+
280
+ static Button* floatbar_create_button(wfFloatBar* const floatbar, const int type, const int resid,
281
+ const int resid_act, const int x, const int y, const int h,
282
+ const int w)
283
+ {
284
+ Button* button = (Button*)calloc(1, sizeof(Button));
285
+
286
+ if (!button)
287
+ return NULL;
288
+
289
+ button->floatbar = floatbar;
290
+ button->type = type;
291
+ button->x = x;
292
+ button->y = y;
293
+ button->w = w;
294
+ button->h = h;
295
+ button->active = FALSE;
296
+ button->bmp = (HBITMAP)LoadImage(floatbar->root_window, MAKEINTRESOURCE(resid), IMAGE_BITMAP, 0,
297
+ 0, LR_DEFAULTCOLOR);
298
+ button->bmp_act = (HBITMAP)LoadImage(floatbar->root_window, MAKEINTRESOURCE(resid_act),
299
+ IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
300
+ return button;
301
+ }
302
+
303
+ static Button* floatbar_create_lock_button(wfFloatBar* const floatbar, const int unlock_resid,
304
+ const int unlock_resid_act, const int lock_resid,
305
+ const int lock_resid_act, const int x, const int y,
306
+ const int h, const int w)
307
+ {
308
+ Button* button = floatbar_create_button(floatbar, BUTTON_LOCKPIN, unlock_resid,
309
+ unlock_resid_act, x, y, h, w);
310
+
311
+ if (!button)
312
+ return NULL;
313
+
314
+ button->unlocked_bmp = button->bmp;
315
+ button->unlocked_bmp_act = button->bmp_act;
316
+ button->locked_bmp = (HBITMAP)LoadImage(floatbar->wfc->hInstance, MAKEINTRESOURCE(lock_resid),
317
+ IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
318
+ button->locked_bmp_act =
319
+ (HBITMAP)LoadImage(floatbar->wfc->hInstance, MAKEINTRESOURCE(lock_resid_act), IMAGE_BITMAP,
320
+ 0, 0, LR_DEFAULTCOLOR);
321
+ return button;
322
+ }
323
+
324
+ static Button* floatbar_get_button(const wfFloatBar* const floatbar, const int x, const int y)
325
+ {
326
+ if ((y > BUTTON_Y) && (y < BUTTON_Y + BUTTON_HEIGHT))
327
+ {
328
+ for (int i = 0; i < BTN_MAX; i++)
329
+ {
330
+ if ((floatbar->buttons[i] != NULL) && (x > floatbar->buttons[i]->x) &&
331
+ (x < floatbar->buttons[i]->x + floatbar->buttons[i]->w))
332
+ {
333
+ return floatbar->buttons[i];
334
+ }
335
+ }
336
+ }
337
+
338
+ return NULL;
339
+ }
340
+
341
+ static BOOL floatbar_paint(wfFloatBar* const floatbar, const HDC hdc)
342
+ {
343
+ HPEN hpen;
344
+ HGDIOBJECT orig;
345
+ /* paint background */
346
+ GRADIENT_RECT gradientRect = { 0, 1 };
347
+ COLORREF rgbTop = RGB(117, 154, 198);
348
+ COLORREF rgbBottom = RGB(6, 55, 120);
349
+ const int top = 0;
350
+ int left = 0;
351
+ int bottom = BACKGROUND_H - 1;
352
+ int right = BACKGROUND_W - 1;
353
+ const int angleOffset = BACKGROUND_H - 1;
354
+ TRIVERTEX triVertext[2] = { { left, top, GetRValue(rgbTop) << 8, GetGValue(rgbTop) << 8,
355
+ GetBValue(rgbTop) << 8, 0x0000 },
356
+ { right, bottom, GetRValue(rgbBottom) << 8,
357
+ GetGValue(rgbBottom) << 8, GetBValue(rgbBottom) << 8, 0x0000 } };
358
+
359
+ if (!floatbar)
360
+ return FALSE;
361
+
362
+ GradientFill(hdc, triVertext, 2, &gradientRect, 1, GRADIENT_FILL_RECT_V);
363
+ /* paint shadow */
364
+ hpen = CreatePen(PS_SOLID, 1, RGB(71, 71, 71));
365
+ orig = SelectObject(hdc, hpen);
366
+ MoveToEx(hdc, left, top, NULL);
367
+ LineTo(hdc, left + angleOffset, bottom);
368
+ LineTo(hdc, right - angleOffset, bottom);
369
+ LineTo(hdc, right + 1, top - 1);
370
+ DeleteObject(hpen);
371
+ hpen = CreatePen(PS_SOLID, 1, RGB(107, 141, 184));
372
+ SelectObject(hdc, hpen);
373
+ left += 1;
374
+ bottom -= 1;
375
+ right -= 1;
376
+ MoveToEx(hdc, left, top, NULL);
377
+ LineTo(hdc, left + (angleOffset - 1), bottom);
378
+ LineTo(hdc, right - (angleOffset - 1), bottom);
379
+ LineTo(hdc, right + 1, top - 1);
380
+ DeleteObject(hpen);
381
+ SelectObject(hdc, orig);
382
+ DrawText(hdc, floatbar->wfc->window_title, wcslen(floatbar->wfc->window_title),
383
+ &floatbar->textRect,
384
+ DT_CENTER | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX | DT_SINGLELINE);
385
+
386
+ /* paint buttons */
387
+
388
+ for (int i = 0; i < BTN_MAX; i++)
389
+ button_paint(floatbar->buttons[i], hdc);
390
+
391
+ return TRUE;
392
+ }
393
+
394
+ static LRESULT CALLBACK floatbar_proc(const HWND hWnd, const UINT Msg, const WPARAM wParam,
395
+ const LPARAM lParam)
396
+ {
397
+ static int dragging = FALSE;
398
+ static int lbtn_dwn = FALSE;
399
+ static int btn_dwn_x = 0;
400
+ static wfFloatBar* floatbar;
401
+ static TRACKMOUSEEVENT tme;
402
+ PAINTSTRUCT ps;
403
+ Button* button;
404
+ HDC hdc;
405
+ int pos_x;
406
+ int pos_y;
407
+ NONCLIENTMETRICS ncm;
408
+ int xScreen = GetSystemMetrics(SM_CXSCREEN);
409
+
410
+ switch (Msg)
411
+ {
412
+ case WM_CREATE:
413
+ floatbar = ((wfFloatBar*)((CREATESTRUCT*)lParam)->lpCreateParams);
414
+ floatbar->hwnd = hWnd;
415
+ GetWindowRect(floatbar->hwnd, &floatbar->rect);
416
+ floatbar->width = floatbar->rect.right - floatbar->rect.left;
417
+ floatbar->height = floatbar->rect.bottom - floatbar->rect.top;
418
+ hdc = GetDC(hWnd);
419
+ floatbar->hdcmem = CreateCompatibleDC(hdc);
420
+ ReleaseDC(hWnd, hdc);
421
+ tme.cbSize = sizeof(TRACKMOUSEEVENT);
422
+ tme.dwFlags = TME_LEAVE;
423
+ tme.hwndTrack = hWnd;
424
+ tme.dwHoverTime = HOVER_DEFAULT;
425
+ // Use caption font, white, draw transparent
426
+ GetClientRect(hWnd, &floatbar->textRect);
427
+ InflateRect(&floatbar->textRect, -TEXT_X, 0);
428
+ SetBkMode(hdc, TRANSPARENT);
429
+ SetTextColor(hdc, RGB(255, 255, 255));
430
+ ncm.cbSize = sizeof(NONCLIENTMETRICS);
431
+ SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0);
432
+ SelectObject(hdc, CreateFontIndirect(&ncm.lfCaptionFont));
433
+ floatbar_trigger_hide(floatbar);
434
+ break;
435
+
436
+ case WM_PAINT:
437
+ hdc = BeginPaint(hWnd, &ps);
438
+ floatbar_paint(floatbar, hdc);
439
+ EndPaint(hWnd, &ps);
440
+ break;
441
+
442
+ case WM_LBUTTONDOWN:
443
+ pos_x = lParam & 0xffff;
444
+ pos_y = (lParam >> 16) & 0xffff;
445
+ button = floatbar_get_button(floatbar, pos_x, pos_y);
446
+
447
+ if (!button)
448
+ {
449
+ SetCapture(hWnd);
450
+ dragging = TRUE;
451
+ btn_dwn_x = lParam & 0xffff;
452
+ }
453
+ else
454
+ lbtn_dwn = TRUE;
455
+
456
+ break;
457
+
458
+ case WM_LBUTTONUP:
459
+ pos_x = lParam & 0xffff;
460
+ pos_y = (lParam >> 16) & 0xffff;
461
+ ReleaseCapture();
462
+ dragging = FALSE;
463
+
464
+ if (lbtn_dwn)
465
+ {
466
+ button = floatbar_get_button(floatbar, pos_x, pos_y);
467
+
468
+ if (button)
469
+ button_hit(button);
470
+
471
+ lbtn_dwn = FALSE;
472
+ }
473
+
474
+ break;
475
+
476
+ case WM_MOUSEMOVE:
477
+ pos_x = lParam & 0xffff;
478
+ pos_y = (lParam >> 16) & 0xffff;
479
+
480
+ if (!floatbar->locked)
481
+ floatbar_animation(floatbar, TRUE);
482
+
483
+ if (dragging)
484
+ {
485
+ floatbar->rect.left = floatbar->rect.left + (lParam & 0xffff) - btn_dwn_x;
486
+
487
+ if (floatbar->rect.left < 0)
488
+ floatbar->rect.left = 0;
489
+ else if (floatbar->rect.left > xScreen - floatbar->width)
490
+ floatbar->rect.left = xScreen - floatbar->width;
491
+
492
+ MoveWindow(hWnd, floatbar->rect.left, 0, floatbar->width, floatbar->height, TRUE);
493
+ }
494
+ else
495
+ {
496
+ for (int i = 0; i < BTN_MAX; i++)
497
+ {
498
+ if (floatbar->buttons[i] != NULL)
499
+ {
500
+ floatbar->buttons[i]->active = FALSE;
501
+ }
502
+ }
503
+
504
+ button = floatbar_get_button(floatbar, pos_x, pos_y);
505
+
506
+ if (button)
507
+ button->active = TRUE;
508
+
509
+ InvalidateRect(hWnd, NULL, FALSE);
510
+ UpdateWindow(hWnd);
511
+ }
512
+
513
+ TrackMouseEvent(&tme);
514
+ break;
515
+
516
+ case WM_CAPTURECHANGED:
517
+ dragging = FALSE;
518
+ break;
519
+
520
+ case WM_MOUSELEAVE:
521
+ {
522
+ for (int i = 0; i < BTN_MAX; i++)
523
+ {
524
+ if (floatbar->buttons[i] != NULL)
525
+ {
526
+ floatbar->buttons[i]->active = FALSE;
527
+ }
528
+ }
529
+
530
+ InvalidateRect(hWnd, NULL, FALSE);
531
+ UpdateWindow(hWnd);
532
+ floatbar_trigger_hide(floatbar);
533
+ break;
534
+ }
535
+
536
+ case WM_TIMER:
537
+ switch (wParam)
538
+ {
539
+ case TIMER_HIDE:
540
+ floatbar_animation(floatbar, FALSE);
541
+ break;
542
+
543
+ case TIMER_ANIMAT_SHOW:
544
+ {
545
+ floatbar->offset--;
546
+ MoveWindow(floatbar->hwnd, floatbar->rect.left, -floatbar->offset,
547
+ floatbar->width, floatbar->height, TRUE);
548
+
549
+ if (floatbar->offset <= 0)
550
+ floatbar_show(floatbar);
551
+
552
+ break;
553
+ }
554
+
555
+ case TIMER_ANIMAT_HIDE:
556
+ {
557
+ floatbar->offset++;
558
+ MoveWindow(floatbar->hwnd, floatbar->rect.left, -floatbar->offset,
559
+ floatbar->width, floatbar->height, TRUE);
560
+
561
+ if (floatbar->offset >= floatbar->height - 2)
562
+ floatbar_hide(floatbar);
563
+
564
+ break;
565
+ }
566
+
567
+ default:
568
+ break;
569
+ }
570
+
571
+ break;
572
+
573
+ case WM_DESTROY:
574
+ DeleteDC(floatbar->hdcmem);
575
+ PostQuitMessage(0);
576
+ break;
577
+
578
+ default:
579
+ return DefWindowProc(hWnd, Msg, wParam, lParam);
580
+ }
581
+
582
+ return 0;
583
+ }
584
+
585
+ static BOOL floatbar_window_create(wfFloatBar* floatbar)
586
+ {
587
+ WNDCLASSEX wnd_cls;
588
+ HWND barWnd;
589
+ HRGN hRgn;
590
+ POINT pt[4];
591
+ RECT rect;
592
+ LONG x;
593
+
594
+ if (!floatbar)
595
+ return FALSE;
596
+
597
+ if (!GetWindowRect(floatbar->parent, &rect))
598
+ return FALSE;
599
+
600
+ x = (rect.right - rect.left - BACKGROUND_W) / 2;
601
+ wnd_cls.cbSize = sizeof(WNDCLASSEX);
602
+ wnd_cls.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
603
+ wnd_cls.lpfnWndProc = floatbar_proc;
604
+ wnd_cls.cbClsExtra = 0;
605
+ wnd_cls.cbWndExtra = 0;
606
+ wnd_cls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
607
+ wnd_cls.hCursor = LoadCursor(floatbar->root_window, IDC_ARROW);
608
+ wnd_cls.hbrBackground = NULL;
609
+ wnd_cls.lpszMenuName = NULL;
610
+ wnd_cls.lpszClassName = L"floatbar";
611
+ wnd_cls.hInstance = floatbar->root_window;
612
+ wnd_cls.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
613
+ RegisterClassEx(&wnd_cls);
614
+ barWnd = CreateWindowEx(WS_EX_TOPMOST, L"floatbar", L"floatbar", WS_CHILD, x, 0, BACKGROUND_W,
615
+ BACKGROUND_H, floatbar->parent, NULL, floatbar->root_window, floatbar);
616
+
617
+ if (barWnd == NULL)
618
+ return FALSE;
619
+
620
+ pt[0].x = 0;
621
+ pt[0].y = 0;
622
+ pt[1].x = BACKGROUND_W;
623
+ pt[1].y = 0;
624
+ pt[2].x = BACKGROUND_W - BACKGROUND_H;
625
+ pt[2].y = BACKGROUND_H;
626
+ pt[3].x = BACKGROUND_H;
627
+ pt[3].y = BACKGROUND_H;
628
+ hRgn = CreatePolygonRgn(pt, 4, ALTERNATE);
629
+ SetWindowRgn(barWnd, hRgn, TRUE);
630
+ return TRUE;
631
+ }
632
+
633
+ void wf_floatbar_free(wfFloatBar* floatbar)
634
+ {
635
+ if (!floatbar)
636
+ return;
637
+
638
+ free(floatbar);
639
+ }
640
+
641
+ wfFloatBar* wf_floatbar_new(wfContext* wfc, HINSTANCE window, DWORD flags)
642
+ {
643
+ wfFloatBar* floatbar;
644
+
645
+ /* Floatbar not enabled */
646
+ if ((flags & 0x0001) == 0)
647
+ return NULL;
648
+
649
+ if (!wfc)
650
+ return NULL;
651
+
652
+ // TODO: Disable for remote app
653
+ floatbar = (wfFloatBar*)calloc(1, sizeof(wfFloatBar));
654
+
655
+ if (!floatbar)
656
+ return NULL;
657
+
658
+ floatbar->root_window = window;
659
+ floatbar->flags = flags;
660
+ floatbar->wfc = wfc;
661
+ floatbar->locked = (flags & 0x0002) != 0;
662
+ floatbar->shown = (flags & 0x0006) != 0; /* If it is loked or shown show it */
663
+ floatbar->hwnd = NULL;
664
+ floatbar->parent = wfc->hwnd;
665
+ floatbar->hdcmem = NULL;
666
+
667
+ if (wfc->fullscreen_toggle)
668
+ {
669
+ floatbar->buttons[0] =
670
+ floatbar_create_button(floatbar, BUTTON_MINIMIZE, IDB_MINIMIZE, IDB_MINIMIZE_ACT,
671
+ MINIMIZE_X, BUTTON_Y, BUTTON_HEIGHT, BUTTON_WIDTH);
672
+ floatbar->buttons[1] =
673
+ floatbar_create_button(floatbar, BUTTON_RESTORE, IDB_RESTORE, IDB_RESTORE_ACT,
674
+ RESTORE_X, BUTTON_Y, BUTTON_HEIGHT, BUTTON_WIDTH);
675
+ }
676
+ else
677
+ {
678
+ floatbar->buttons[0] = NULL;
679
+ floatbar->buttons[1] = NULL;
680
+ }
681
+
682
+ floatbar->buttons[2] = floatbar_create_button(floatbar, BUTTON_CLOSE, IDB_CLOSE, IDB_CLOSE_ACT,
683
+ CLOSE_X, BUTTON_Y, BUTTON_HEIGHT, BUTTON_WIDTH);
684
+ floatbar->buttons[3] =
685
+ floatbar_create_lock_button(floatbar, IDB_UNLOCK, IDB_UNLOCK_ACT, IDB_LOCK, IDB_LOCK_ACT,
686
+ LOCK_X, BUTTON_Y, BUTTON_HEIGHT, BUTTON_WIDTH);
687
+
688
+ if (!floatbar_window_create(floatbar))
689
+ goto fail;
690
+
691
+ if (!update_locked_state(floatbar))
692
+ goto fail;
693
+
694
+ if (!wf_floatbar_toggle_fullscreen(
695
+ floatbar, freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_Fullscreen)))
696
+ goto fail;
697
+
698
+ return floatbar;
699
+ fail:
700
+ wf_floatbar_free(floatbar);
701
+ return NULL;
702
+ }
703
+
704
+ BOOL wf_floatbar_toggle_fullscreen(wfFloatBar* floatbar, BOOL fullscreen)
705
+ {
706
+ BOOL show_fs, show_wn;
707
+
708
+ if (!floatbar)
709
+ return FALSE;
710
+
711
+ show_fs = (floatbar->flags & 0x0010) != 0;
712
+ show_wn = (floatbar->flags & 0x0020) != 0;
713
+
714
+ if ((show_fs && fullscreen) || (show_wn && !fullscreen))
715
+ {
716
+ ShowWindow(floatbar->hwnd, SW_SHOWNORMAL);
717
+ Sleep(10);
718
+
719
+ if (floatbar->shown)
720
+ floatbar_show(floatbar);
721
+ else
722
+ floatbar_hide(floatbar);
723
+ }
724
+ else
725
+ {
726
+ ShowWindow(floatbar->hwnd, SW_HIDE);
727
+ }
728
+
729
+ return TRUE;
730
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_floatbar.h ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Windows Float Bar
4
+ *
5
+ * Copyright 2013 Zhang Zhaolong <[email protected]>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ #ifndef FREERDP_CLIENT_WIN_FLOATBAR_H
21
+ #define FREERDP_CLIENT_WIN_FLOATBAR_H
22
+
23
+ #include <winpr/crt.h>
24
+
25
+ typedef struct s_FloatBar wfFloatBar;
26
+ typedef struct wf_context wfContext;
27
+
28
+ wfFloatBar* wf_floatbar_new(wfContext* wfc, HINSTANCE window, DWORD flags);
29
+ void wf_floatbar_free(wfFloatBar* floatbar);
30
+
31
+ BOOL wf_floatbar_toggle_fullscreen(wfFloatBar* floatbar, BOOL fullscreen);
32
+
33
+ #endif /* FREERDP_CLIENT_WIN_FLOATBAR_H */
local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_gdi.c ADDED
@@ -0,0 +1,848 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Windows GDI
4
+ *
5
+ * Copyright 2009-2011 Jay Sorg
6
+ * Copyright 2010-2011 Vic Lee
7
+ * Copyright 2010-2011 Marc-Andre Moreau <[email protected]>
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+
22
+ #include <freerdp/config.h>
23
+
24
+ #include <stdio.h>
25
+ #include <stdlib.h>
26
+ #include <string.h>
27
+ #include <conio.h>
28
+
29
+ #include <freerdp/log.h>
30
+ #include <freerdp/gdi/gdi.h>
31
+ #include <freerdp/constants.h>
32
+ #include <freerdp/codec/color.h>
33
+ #include <freerdp/codec/bitmap.h>
34
+ #include <freerdp/codec/rfx.h>
35
+ #include <freerdp/codec/nsc.h>
36
+ #include <freerdp/gdi/gdi.h>
37
+
38
+ #include "wf_client.h"
39
+ #include "wf_graphics.h"
40
+ #include "wf_gdi.h"
41
+
42
+ #define TAG CLIENT_TAG("windows.gdi")
43
+
44
+ static const BYTE wf_rop2_table[] = {
45
+ R2_BLACK, /* 0 */
46
+ R2_NOTMERGEPEN, /* DPon */
47
+ R2_MASKNOTPEN, /* DPna */
48
+ R2_NOTCOPYPEN, /* Pn */
49
+ R2_MASKPENNOT, /* PDna */
50
+ R2_NOT, /* Dn */
51
+ R2_XORPEN, /* DPx */
52
+ R2_NOTMASKPEN, /* DPan */
53
+ R2_MASKPEN, /* DPa */
54
+ R2_NOTXORPEN, /* DPxn */
55
+ R2_NOP, /* D */
56
+ R2_MERGENOTPEN, /* DPno */
57
+ R2_COPYPEN, /* P */
58
+ R2_MERGEPENNOT, /* PDno */
59
+ R2_MERGEPEN, /* PDo */
60
+ R2_WHITE, /* 1 */
61
+ };
62
+
63
+ static BOOL wf_decode_color(wfContext* wfc, const UINT32 srcColor, COLORREF* color, UINT32* format)
64
+ {
65
+ rdpGdi* gdi;
66
+ rdpSettings* settings;
67
+ UINT32 SrcFormat, DstFormat;
68
+
69
+ if (!wfc)
70
+ return FALSE;
71
+
72
+ gdi = wfc->common.context.gdi;
73
+ settings = wfc->common.context.settings;
74
+
75
+ if (!gdi || !settings)
76
+ return FALSE;
77
+
78
+ SrcFormat = gdi_get_pixel_format(freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth));
79
+
80
+ if (format)
81
+ *format = SrcFormat;
82
+
83
+ switch (FreeRDPGetBitsPerPixel(gdi->dstFormat))
84
+ {
85
+ case 32:
86
+ DstFormat = PIXEL_FORMAT_ABGR32;
87
+ break;
88
+
89
+ case 24:
90
+ DstFormat = PIXEL_FORMAT_BGR24;
91
+ break;
92
+
93
+ case 16:
94
+ DstFormat = PIXEL_FORMAT_RGB16;
95
+ break;
96
+
97
+ default:
98
+ return FALSE;
99
+ }
100
+
101
+ *color = FreeRDPConvertColor(srcColor, SrcFormat, DstFormat, &gdi->palette);
102
+ return TRUE;
103
+ }
104
+
105
+ static BOOL wf_set_rop2(HDC hdc, int rop2)
106
+ {
107
+ if ((rop2 < 0x01) || (rop2 > 0x10))
108
+ {
109
+ WLog_ERR(TAG, "Unsupported ROP2: %d", rop2);
110
+ return FALSE;
111
+ }
112
+
113
+ SetROP2(hdc, wf_rop2_table[rop2 - 1]);
114
+ return TRUE;
115
+ }
116
+
117
+ static wfBitmap* wf_glyph_new(wfContext* wfc, GLYPH_DATA* glyph)
118
+ {
119
+ wfBitmap* glyph_bmp;
120
+ glyph_bmp = wf_image_new(wfc, glyph->cx, glyph->cy, PIXEL_FORMAT_MONO, glyph->aj);
121
+ return glyph_bmp;
122
+ }
123
+
124
+ static void wf_glyph_free(wfBitmap* glyph)
125
+ {
126
+ wf_image_free(glyph);
127
+ }
128
+
129
+ static BYTE* wf_glyph_convert(wfContext* wfc, int width, int height, const BYTE* data)
130
+ {
131
+ const int src_bytes_per_row = (width + 7) / 8;
132
+ const int dst_bytes_per_row = src_bytes_per_row + (src_bytes_per_row % 2);
133
+ BYTE* cdata = (BYTE*)malloc(dst_bytes_per_row * height);
134
+ const BYTE* src = data;
135
+
136
+ for (int indexy = 0; indexy < height; indexy++)
137
+ {
138
+ BYTE* dst = &cdata[1ull * indexy * dst_bytes_per_row];
139
+
140
+ for (int indexx = 0; indexx < dst_bytes_per_row; indexx++)
141
+ {
142
+ if (indexx < src_bytes_per_row)
143
+ *dst++ = *src++;
144
+ else
145
+ *dst++ = 0;
146
+ }
147
+ }
148
+
149
+ return cdata;
150
+ }
151
+
152
+ static HBRUSH wf_create_brush(wfContext* wfc, rdpBrush* brush, UINT32 color, UINT32 bpp)
153
+ {
154
+ HBRUSH br;
155
+ LOGBRUSH lbr;
156
+ BYTE* cdata;
157
+ BYTE ipattern[8];
158
+ HBITMAP pattern = NULL;
159
+ lbr.lbStyle = brush->style;
160
+
161
+ if (lbr.lbStyle == BS_DIBPATTERN || lbr.lbStyle == BS_DIBPATTERN8X8 ||
162
+ lbr.lbStyle == BS_DIBPATTERNPT)
163
+ lbr.lbColor = DIB_RGB_COLORS;
164
+ else
165
+ lbr.lbColor = color;
166
+
167
+ if (lbr.lbStyle == BS_PATTERN || lbr.lbStyle == BS_PATTERN8X8)
168
+ {
169
+ if (brush->bpp > 1)
170
+ {
171
+ UINT32 format = gdi_get_pixel_format(bpp);
172
+ pattern = wf_create_dib(wfc, 8, 8, format, brush->data, NULL);
173
+ lbr.lbHatch = (ULONG_PTR)pattern;
174
+ }
175
+ else
176
+ {
177
+ for (UINT32 i = 0; i != 8; i++)
178
+ ipattern[7 - i] = brush->data[i];
179
+
180
+ cdata = wf_glyph_convert(wfc, 8, 8, ipattern);
181
+ pattern = CreateBitmap(8, 8, 1, 1, cdata);
182
+ lbr.lbHatch = (ULONG_PTR)pattern;
183
+ free(cdata);
184
+ }
185
+ }
186
+ else if (lbr.lbStyle == BS_HATCHED)
187
+ {
188
+ lbr.lbHatch = brush->hatch;
189
+ }
190
+ else
191
+ {
192
+ lbr.lbHatch = 0;
193
+ }
194
+
195
+ br = CreateBrushIndirect(&lbr);
196
+ SetBrushOrgEx(wfc->drawing->hdc, brush->x, brush->y, NULL);
197
+
198
+ if (pattern != NULL)
199
+ DeleteObject(pattern);
200
+
201
+ return br;
202
+ }
203
+
204
+ BOOL wf_scale_rect(wfContext* wfc, RECT* source)
205
+ {
206
+ UINT32 ww, wh, dw, dh;
207
+ rdpSettings* settings;
208
+
209
+ if (!wfc || !source || !wfc->common.context.settings)
210
+ return FALSE;
211
+
212
+ settings = wfc->common.context.settings;
213
+
214
+ if (!settings)
215
+ return FALSE;
216
+
217
+ dw = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
218
+ dh = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
219
+
220
+ if (!wfc->client_width)
221
+ wfc->client_width = dw;
222
+
223
+ if (!wfc->client_height)
224
+ wfc->client_height = dh;
225
+
226
+ ww = wfc->client_width;
227
+ wh = wfc->client_height;
228
+
229
+ if (!ww)
230
+ ww = dw;
231
+
232
+ if (!wh)
233
+ wh = dh;
234
+
235
+ if (freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_SmartSizing) &&
236
+ (ww != dw || wh != dh))
237
+ {
238
+ source->bottom = source->bottom * wh / dh + 20;
239
+ source->top = source->top * wh / dh - 20;
240
+ source->left = source->left * ww / dw - 20;
241
+ source->right = source->right * ww / dw + 20;
242
+ }
243
+
244
+ source->bottom -= wfc->yCurrentScroll;
245
+ source->top -= wfc->yCurrentScroll;
246
+ source->left -= wfc->xCurrentScroll;
247
+ source->right -= wfc->xCurrentScroll;
248
+ return TRUE;
249
+ }
250
+
251
+ void wf_invalidate_region(wfContext* wfc, UINT32 x, UINT32 y, UINT32 width, UINT32 height)
252
+ {
253
+ RECT rect;
254
+ rdpGdi* gdi = wfc->common.context.gdi;
255
+ wfc->update_rect.left = x + wfc->offset_x;
256
+ wfc->update_rect.top = y + wfc->offset_y;
257
+ wfc->update_rect.right = wfc->update_rect.left + width;
258
+ wfc->update_rect.bottom = wfc->update_rect.top + height;
259
+ wf_scale_rect(wfc, &(wfc->update_rect));
260
+ InvalidateRect(wfc->hwnd, &(wfc->update_rect), FALSE);
261
+ rect.left = x;
262
+ rect.right = width;
263
+ rect.top = y;
264
+ rect.bottom = height;
265
+ wf_scale_rect(wfc, &rect);
266
+ gdi_InvalidateRegion(gdi->primary->hdc, rect.left, rect.top, rect.right, rect.bottom);
267
+ }
268
+
269
+ void wf_update_offset(wfContext* wfc)
270
+ {
271
+ rdpSettings* settings;
272
+ settings = wfc->common.context.settings;
273
+
274
+ if (wfc->fullscreen)
275
+ {
276
+ if (freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_UseMultimon))
277
+ {
278
+ int x = GetSystemMetrics(SM_XVIRTUALSCREEN);
279
+ int y = GetSystemMetrics(SM_YVIRTUALSCREEN);
280
+ int w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
281
+ int h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
282
+ wfc->offset_x = (w - freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth)) / 2;
283
+
284
+ if (wfc->offset_x < x)
285
+ wfc->offset_x = x;
286
+
287
+ wfc->offset_y = (h - freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)) / 2;
288
+
289
+ if (wfc->offset_y < y)
290
+ wfc->offset_y = y;
291
+ }
292
+ else
293
+ {
294
+ wfc->offset_x = (GetSystemMetrics(SM_CXSCREEN) -
295
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth)) /
296
+ 2;
297
+
298
+ if (wfc->offset_x < 0)
299
+ wfc->offset_x = 0;
300
+
301
+ wfc->offset_y = (GetSystemMetrics(SM_CYSCREEN) -
302
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)) /
303
+ 2;
304
+
305
+ if (wfc->offset_y < 0)
306
+ wfc->offset_y = 0;
307
+ }
308
+ }
309
+ else
310
+ {
311
+ wfc->offset_x = 0;
312
+ wfc->offset_y = 0;
313
+ }
314
+ }
315
+
316
+ void wf_resize_window(wfContext* wfc)
317
+ {
318
+ rdpSettings* settings;
319
+ settings = wfc->common.context.settings;
320
+
321
+ if (wfc->fullscreen)
322
+ {
323
+ if (freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_UseMultimon))
324
+ {
325
+ int x = GetSystemMetrics(SM_XVIRTUALSCREEN);
326
+ int y = GetSystemMetrics(SM_YVIRTUALSCREEN);
327
+ int w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
328
+ int h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
329
+ SetWindowLongPtr(wfc->hwnd, GWL_STYLE, WS_POPUP);
330
+ SetWindowPos(wfc->hwnd, HWND_TOP, x, y, w, h, SWP_FRAMECHANGED);
331
+ }
332
+ else
333
+ {
334
+ SetWindowLongPtr(wfc->hwnd, GWL_STYLE, WS_POPUP);
335
+ SetWindowPos(wfc->hwnd, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN),
336
+ GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED);
337
+ }
338
+ }
339
+ else if (!freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_Decorations))
340
+ {
341
+ SetWindowLongPtr(wfc->hwnd, GWL_STYLE, WS_CHILD);
342
+
343
+ if (freerdp_settings_get_bool(settings, FreeRDP_EmbeddedWindow))
344
+ {
345
+ if (!wfc->client_height)
346
+ wfc->client_height = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
347
+
348
+ if (!wfc->client_width)
349
+ wfc->client_width = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
350
+
351
+ wf_update_canvas_diff(wfc);
352
+ /* Now resize to get full canvas size and room for caption and borders */
353
+ SetWindowPos(wfc->hwnd, HWND_TOP, wfc->client_x, wfc->client_y,
354
+ wfc->client_width + wfc->diff.x, wfc->client_height + wfc->diff.y,
355
+ 0 /*SWP_FRAMECHANGED*/);
356
+ }
357
+ else
358
+ {
359
+ /* Now resize to get full canvas size and room for caption and borders */
360
+ SetWindowPos(wfc->hwnd, HWND_TOP, 0, 0,
361
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
362
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight),
363
+ SWP_FRAMECHANGED);
364
+ wf_update_canvas_diff(wfc);
365
+ SetWindowPos(wfc->hwnd, HWND_TOP, -1, -1,
366
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) + wfc->diff.x,
367
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) + wfc->diff.y,
368
+ SWP_NOMOVE | SWP_FRAMECHANGED);
369
+ }
370
+ }
371
+ else
372
+ {
373
+ SetWindowLongPtr(wfc->hwnd, GWL_STYLE,
374
+ WS_CAPTION | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_SIZEBOX |
375
+ WS_MAXIMIZEBOX);
376
+
377
+ if (!wfc->client_height)
378
+ wfc->client_height = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
379
+
380
+ if (!wfc->client_width)
381
+ wfc->client_width = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
382
+
383
+ if (!wfc->client_x)
384
+ wfc->client_x = 10;
385
+
386
+ if (!wfc->client_y)
387
+ wfc->client_y = 10;
388
+
389
+ wf_update_canvas_diff(wfc);
390
+ /* Now resize to get full canvas size and room for caption and borders */
391
+ int width, height;
392
+ if (freerdp_settings_get_bool(settings, FreeRDP_SmartSizing) &&
393
+ freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingWidth) &&
394
+ freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingHeight))
395
+ {
396
+ width = freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingWidth);
397
+ height = freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingHeight);
398
+ }
399
+ else
400
+ {
401
+ width = wfc->client_width + wfc->diff.x;
402
+ height = wfc->client_height + wfc->diff.y;
403
+ }
404
+
405
+ int xpos, ypos;
406
+ if ((freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosX) != UINT32_MAX) &&
407
+ (freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosY) != UINT32_MAX))
408
+ {
409
+ xpos = freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosX);
410
+ ypos = freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosY);
411
+ }
412
+ else
413
+ {
414
+ xpos = wfc->client_x;
415
+ ypos = wfc->client_y;
416
+ }
417
+ SetWindowPos(wfc->hwnd, HWND_TOP, xpos, ypos, width, height, 0 /*SWP_FRAMECHANGED*/);
418
+ // wf_size_scrollbars(wfc, wfc->client_width, wfc->client_height);
419
+ }
420
+
421
+ wf_update_offset(wfc);
422
+ }
423
+
424
+ void wf_toggle_fullscreen(wfContext* wfc)
425
+ {
426
+ ShowWindow(wfc->hwnd, SW_HIDE);
427
+ wfc->fullscreen = !wfc->fullscreen;
428
+
429
+ if (wfc->fullscreen)
430
+ {
431
+ wfc->disablewindowtracking = TRUE;
432
+ }
433
+
434
+ wf_floatbar_toggle_fullscreen(wfc->floatbar, wfc->fullscreen);
435
+ SetParent(wfc->hwnd, wfc->fullscreen ? NULL : wfc->hWndParent);
436
+ wf_resize_window(wfc);
437
+ ShowWindow(wfc->hwnd, SW_SHOW);
438
+ SetForegroundWindow(wfc->hwnd);
439
+
440
+ if (!wfc->fullscreen)
441
+ {
442
+ // Re-enable window tracking AFTER resizing it back, otherwise it can lean to repositioning
443
+ // errors.
444
+ wfc->disablewindowtracking = FALSE;
445
+ }
446
+ }
447
+
448
+ static BOOL wf_gdi_palette_update(rdpContext* context, const PALETTE_UPDATE* palette)
449
+ {
450
+ return TRUE;
451
+ }
452
+
453
+ void wf_set_null_clip_rgn(wfContext* wfc)
454
+ {
455
+ SelectClipRgn(wfc->drawing->hdc, NULL);
456
+ }
457
+
458
+ void wf_set_clip_rgn(wfContext* wfc, int x, int y, int width, int height)
459
+ {
460
+ HRGN clip;
461
+ clip = CreateRectRgn(x, y, x + width, y + height);
462
+ SelectClipRgn(wfc->drawing->hdc, clip);
463
+ DeleteObject(clip);
464
+ }
465
+
466
+ static BOOL wf_gdi_set_bounds(rdpContext* context, const rdpBounds* bounds)
467
+ {
468
+ HRGN hrgn;
469
+ wfContext* wfc = (wfContext*)context;
470
+
471
+ if (!context || !bounds)
472
+ return FALSE;
473
+
474
+ if (bounds != NULL)
475
+ {
476
+ hrgn = CreateRectRgn(bounds->left, bounds->top, bounds->right + 1, bounds->bottom + 1);
477
+ SelectClipRgn(wfc->drawing->hdc, hrgn);
478
+ DeleteObject(hrgn);
479
+ }
480
+ else
481
+ SelectClipRgn(wfc->drawing->hdc, NULL);
482
+
483
+ return TRUE;
484
+ }
485
+
486
+ static BOOL wf_gdi_dstblt(rdpContext* context, const DSTBLT_ORDER* dstblt)
487
+ {
488
+ wfContext* wfc = (wfContext*)context;
489
+
490
+ if (!context || !dstblt)
491
+ return FALSE;
492
+
493
+ if (!BitBlt(wfc->drawing->hdc, dstblt->nLeftRect, dstblt->nTopRect, dstblt->nWidth,
494
+ dstblt->nHeight, NULL, 0, 0, gdi_rop3_code(dstblt->bRop)))
495
+ return FALSE;
496
+
497
+ wf_invalidate_region(wfc, dstblt->nLeftRect, dstblt->nTopRect, dstblt->nWidth, dstblt->nHeight);
498
+ return TRUE;
499
+ }
500
+
501
+ static BOOL wf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
502
+ {
503
+ HBRUSH brush;
504
+ HBRUSH org_brush;
505
+ int org_bkmode;
506
+ COLORREF fgcolor;
507
+ COLORREF bgcolor;
508
+ COLORREF org_bkcolor;
509
+ COLORREF org_textcolor;
510
+ BOOL rc;
511
+ wfContext* wfc = (wfContext*)context;
512
+
513
+ if (!context || !patblt)
514
+ return FALSE;
515
+
516
+ if (!wf_decode_color(wfc, patblt->foreColor, &fgcolor, NULL))
517
+ return FALSE;
518
+
519
+ if (!wf_decode_color(wfc, patblt->backColor, &bgcolor, NULL))
520
+ return FALSE;
521
+
522
+ brush = wf_create_brush(wfc, &patblt->brush, fgcolor,
523
+ freerdp_settings_get_uint32(context->settings, FreeRDP_ColorDepth));
524
+ org_bkmode = SetBkMode(wfc->drawing->hdc, OPAQUE);
525
+ org_bkcolor = SetBkColor(wfc->drawing->hdc, bgcolor);
526
+ org_textcolor = SetTextColor(wfc->drawing->hdc, fgcolor);
527
+ org_brush = (HBRUSH)SelectObject(wfc->drawing->hdc, brush);
528
+ rc = PatBlt(wfc->drawing->hdc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth,
529
+ patblt->nHeight, gdi_rop3_code(patblt->bRop));
530
+ SelectObject(wfc->drawing->hdc, org_brush);
531
+ DeleteObject(brush);
532
+ SetBkMode(wfc->drawing->hdc, org_bkmode);
533
+ SetBkColor(wfc->drawing->hdc, org_bkcolor);
534
+ SetTextColor(wfc->drawing->hdc, org_textcolor);
535
+
536
+ if (wfc->drawing == wfc->primary)
537
+ wf_invalidate_region(wfc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth,
538
+ patblt->nHeight);
539
+
540
+ return rc;
541
+ }
542
+
543
+ static BOOL wf_gdi_scrblt(rdpContext* context, const SCRBLT_ORDER* scrblt)
544
+ {
545
+ wfContext* wfc = (wfContext*)context;
546
+
547
+ if (!context || !scrblt || !wfc->drawing)
548
+ return FALSE;
549
+
550
+ if (!BitBlt(wfc->drawing->hdc, scrblt->nLeftRect, scrblt->nTopRect, scrblt->nWidth,
551
+ scrblt->nHeight, wfc->primary->hdc, scrblt->nXSrc, scrblt->nYSrc,
552
+ gdi_rop3_code(scrblt->bRop)))
553
+ return FALSE;
554
+
555
+ wf_invalidate_region(wfc, scrblt->nLeftRect, scrblt->nTopRect, scrblt->nWidth, scrblt->nHeight);
556
+ return TRUE;
557
+ }
558
+
559
+ static BOOL wf_gdi_opaque_rect(rdpContext* context, const OPAQUE_RECT_ORDER* opaque_rect)
560
+ {
561
+ RECT rect;
562
+ HBRUSH brush;
563
+ COLORREF brush_color;
564
+ wfContext* wfc = (wfContext*)context;
565
+
566
+ if (!context || !opaque_rect)
567
+ return FALSE;
568
+
569
+ if (!wf_decode_color(wfc, opaque_rect->color, &brush_color, NULL))
570
+ return FALSE;
571
+
572
+ rect.left = opaque_rect->nLeftRect;
573
+ rect.top = opaque_rect->nTopRect;
574
+ rect.right = opaque_rect->nLeftRect + opaque_rect->nWidth;
575
+ rect.bottom = opaque_rect->nTopRect + opaque_rect->nHeight;
576
+ brush = CreateSolidBrush(brush_color);
577
+ FillRect(wfc->drawing->hdc, &rect, brush);
578
+ DeleteObject(brush);
579
+
580
+ if (wfc->drawing == wfc->primary)
581
+ wf_invalidate_region(wfc, rect.left, rect.top, rect.right - rect.left + 1,
582
+ rect.bottom - rect.top + 1);
583
+
584
+ return TRUE;
585
+ }
586
+
587
+ static BOOL wf_gdi_multi_opaque_rect(rdpContext* context,
588
+ const MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect)
589
+ {
590
+ RECT rect;
591
+ HBRUSH brush;
592
+ COLORREF brush_color;
593
+ wfContext* wfc = (wfContext*)context;
594
+
595
+ if (!context || !multi_opaque_rect)
596
+ return FALSE;
597
+
598
+ if (!wf_decode_color(wfc, multi_opaque_rect->color, &brush_color, NULL))
599
+ return FALSE;
600
+
601
+ for (UINT32 i = 0; i < multi_opaque_rect->numRectangles; i++)
602
+ {
603
+ const DELTA_RECT* rectangle = &multi_opaque_rect->rectangles[i];
604
+ rect.left = rectangle->left;
605
+ rect.top = rectangle->top;
606
+ rect.right = rectangle->left + rectangle->width;
607
+ rect.bottom = rectangle->top + rectangle->height;
608
+ brush = CreateSolidBrush(brush_color);
609
+ FillRect(wfc->drawing->hdc, &rect, brush);
610
+
611
+ if (wfc->drawing == wfc->primary)
612
+ wf_invalidate_region(wfc, rect.left, rect.top, rect.right - rect.left + 1,
613
+ rect.bottom - rect.top + 1);
614
+
615
+ DeleteObject(brush);
616
+ }
617
+
618
+ return TRUE;
619
+ }
620
+
621
+ static BOOL wf_gdi_line_to(rdpContext* context, const LINE_TO_ORDER* line_to)
622
+ {
623
+ HPEN pen;
624
+ HPEN org_pen;
625
+ int x, y, w, h;
626
+ COLORREF pen_color;
627
+ wfContext* wfc = (wfContext*)context;
628
+
629
+ if (!context || !line_to)
630
+ return FALSE;
631
+
632
+ if (!wf_decode_color(wfc, line_to->penColor, &pen_color, NULL))
633
+ return FALSE;
634
+
635
+ pen = CreatePen(line_to->penStyle, line_to->penWidth, pen_color);
636
+ wf_set_rop2(wfc->drawing->hdc, line_to->bRop2);
637
+ org_pen = (HPEN)SelectObject(wfc->drawing->hdc, pen);
638
+ MoveToEx(wfc->drawing->hdc, line_to->nXStart, line_to->nYStart, NULL);
639
+ LineTo(wfc->drawing->hdc, line_to->nXEnd, line_to->nYEnd);
640
+ x = (line_to->nXStart < line_to->nXEnd) ? line_to->nXStart : line_to->nXEnd;
641
+ y = (line_to->nYStart < line_to->nYEnd) ? line_to->nYStart : line_to->nYEnd;
642
+ w = (line_to->nXStart < line_to->nXEnd) ? (line_to->nXEnd - line_to->nXStart)
643
+ : (line_to->nXStart - line_to->nXEnd);
644
+ h = (line_to->nYStart < line_to->nYEnd) ? (line_to->nYEnd - line_to->nYStart)
645
+ : (line_to->nYStart - line_to->nYEnd);
646
+
647
+ if (wfc->drawing == wfc->primary)
648
+ wf_invalidate_region(wfc, x, y, w, h);
649
+
650
+ SelectObject(wfc->drawing->hdc, org_pen);
651
+ DeleteObject(pen);
652
+ return TRUE;
653
+ }
654
+
655
+ static BOOL wf_gdi_polyline(rdpContext* context, const POLYLINE_ORDER* polyline)
656
+ {
657
+ int org_rop2;
658
+ HPEN hpen;
659
+ HPEN org_hpen;
660
+ COLORREF pen_color;
661
+ wfContext* wfc = (wfContext*)context;
662
+
663
+ if (!context || !polyline)
664
+ return FALSE;
665
+
666
+ if (!wf_decode_color(wfc, polyline->penColor, &pen_color, NULL))
667
+ return FALSE;
668
+
669
+ hpen = CreatePen(0, 1, pen_color);
670
+ org_rop2 = wf_set_rop2(wfc->drawing->hdc, polyline->bRop2);
671
+ org_hpen = (HPEN)SelectObject(wfc->drawing->hdc, hpen);
672
+
673
+ if (polyline->numDeltaEntries > 0)
674
+ {
675
+ POINT* pts;
676
+ POINT temp;
677
+ int numPoints;
678
+ numPoints = polyline->numDeltaEntries + 1;
679
+ pts = (POINT*)malloc(sizeof(POINT) * numPoints);
680
+ pts[0].x = temp.x = polyline->xStart;
681
+ pts[0].y = temp.y = polyline->yStart;
682
+
683
+ for (UINT32 i = 0; i < polyline->numDeltaEntries; i++)
684
+ {
685
+ temp.x += polyline->points[i].x;
686
+ temp.y += polyline->points[i].y;
687
+ pts[i + 1].x = temp.x;
688
+ pts[i + 1].y = temp.y;
689
+ }
690
+
691
+ if (wfc->drawing == wfc->primary)
692
+ wf_invalidate_region(wfc, wfc->client_x, wfc->client_y, wfc->client_width,
693
+ wfc->client_height);
694
+
695
+ Polyline(wfc->drawing->hdc, pts, numPoints);
696
+ free(pts);
697
+ }
698
+
699
+ SelectObject(wfc->drawing->hdc, org_hpen);
700
+ wf_set_rop2(wfc->drawing->hdc, org_rop2);
701
+ DeleteObject(hpen);
702
+ return TRUE;
703
+ }
704
+
705
+ static BOOL wf_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
706
+ {
707
+ wfBitmap* bitmap;
708
+ wfContext* wfc = (wfContext*)context;
709
+
710
+ if (!context || !memblt)
711
+ return FALSE;
712
+
713
+ bitmap = (wfBitmap*)memblt->bitmap;
714
+
715
+ if (!bitmap || !wfc->drawing || !wfc->drawing->hdc)
716
+ return FALSE;
717
+
718
+ if (!BitBlt(wfc->drawing->hdc, memblt->nLeftRect, memblt->nTopRect, memblt->nWidth,
719
+ memblt->nHeight, bitmap->hdc, memblt->nXSrc, memblt->nYSrc,
720
+ gdi_rop3_code(memblt->bRop)))
721
+ return FALSE;
722
+
723
+ if (wfc->drawing == wfc->primary)
724
+ wf_invalidate_region(wfc, memblt->nLeftRect, memblt->nTopRect, memblt->nWidth,
725
+ memblt->nHeight);
726
+
727
+ return TRUE;
728
+ }
729
+
730
+ static BOOL wf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
731
+ {
732
+ BOOL rc = FALSE;
733
+ HDC hdc;
734
+ wfBitmap* bitmap;
735
+ wfContext* wfc = (wfContext*)context;
736
+ COLORREF fgcolor, bgcolor, orgColor;
737
+ HBRUSH orgBrush = NULL, brush = NULL;
738
+
739
+ if (!context || !mem3blt)
740
+ return FALSE;
741
+
742
+ bitmap = (wfBitmap*)mem3blt->bitmap;
743
+
744
+ if (!bitmap || !wfc->drawing || !wfc->drawing->hdc)
745
+ return FALSE;
746
+
747
+ hdc = wfc->drawing->hdc;
748
+
749
+ if (!wf_decode_color(wfc, mem3blt->foreColor, &fgcolor, NULL))
750
+ return FALSE;
751
+
752
+ if (!wf_decode_color(wfc, mem3blt->backColor, &bgcolor, NULL))
753
+ return FALSE;
754
+
755
+ orgColor = SetTextColor(hdc, fgcolor);
756
+
757
+ switch (mem3blt->brush.style)
758
+ {
759
+ case GDI_BS_SOLID:
760
+ brush = CreateSolidBrush(fgcolor);
761
+ break;
762
+
763
+ case GDI_BS_HATCHED:
764
+ case GDI_BS_PATTERN:
765
+ {
766
+ HBITMAP bmp = CreateBitmap(8, 8, 1, mem3blt->brush.bpp, mem3blt->brush.data);
767
+ brush = CreatePatternBrush(bmp);
768
+ }
769
+ break;
770
+
771
+ default:
772
+ goto fail;
773
+ }
774
+
775
+ orgBrush = SelectObject(hdc, brush);
776
+
777
+ if (!BitBlt(hdc, mem3blt->nLeftRect, mem3blt->nTopRect, mem3blt->nWidth, mem3blt->nHeight,
778
+ bitmap->hdc, mem3blt->nXSrc, mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop)))
779
+ goto fail;
780
+
781
+ if (wfc->drawing == wfc->primary)
782
+ wf_invalidate_region(wfc, mem3blt->nLeftRect, mem3blt->nTopRect, mem3blt->nWidth,
783
+ mem3blt->nHeight);
784
+
785
+ rc = TRUE;
786
+ fail:
787
+
788
+ if (brush)
789
+ SelectObject(hdc, orgBrush);
790
+
791
+ SetTextColor(hdc, orgColor);
792
+ return rc;
793
+ }
794
+
795
+ static BOOL wf_gdi_surface_frame_marker(rdpContext* context,
796
+ const SURFACE_FRAME_MARKER* surface_frame_marker)
797
+ {
798
+ rdpSettings* settings;
799
+
800
+ if (!context || !surface_frame_marker || !context->instance)
801
+ return FALSE;
802
+
803
+ settings = context->settings;
804
+
805
+ if (!settings)
806
+ return FALSE;
807
+
808
+ if (surface_frame_marker->frameAction == SURFACECMD_FRAMEACTION_END &&
809
+ freerdp_settings_get_uint32(settings, FreeRDP_FrameAcknowledge) > 0)
810
+ {
811
+ IFCALL(context->update->SurfaceFrameAcknowledge, context, surface_frame_marker->frameId);
812
+ }
813
+
814
+ return TRUE;
815
+ }
816
+
817
+ void wf_gdi_register_update_callbacks(rdpUpdate* update)
818
+ {
819
+ rdpPrimaryUpdate* primary = update->primary;
820
+ update->Palette = wf_gdi_palette_update;
821
+ update->SetBounds = wf_gdi_set_bounds;
822
+ primary->DstBlt = wf_gdi_dstblt;
823
+ primary->PatBlt = wf_gdi_patblt;
824
+ primary->ScrBlt = wf_gdi_scrblt;
825
+ primary->OpaqueRect = wf_gdi_opaque_rect;
826
+ primary->MultiOpaqueRect = wf_gdi_multi_opaque_rect;
827
+ primary->LineTo = wf_gdi_line_to;
828
+ primary->Polyline = wf_gdi_polyline;
829
+ primary->MemBlt = wf_gdi_memblt;
830
+ primary->Mem3Blt = wf_gdi_mem3blt;
831
+ update->SurfaceFrameMarker = wf_gdi_surface_frame_marker;
832
+ }
833
+
834
+ void wf_update_canvas_diff(wfContext* wfc)
835
+ {
836
+ RECT rc_client, rc_wnd;
837
+ int dx, dy;
838
+ GetClientRect(wfc->hwnd, &rc_client);
839
+ GetWindowRect(wfc->hwnd, &rc_wnd);
840
+ dx = (rc_wnd.right - rc_wnd.left) - rc_client.right;
841
+ dy = (rc_wnd.bottom - rc_wnd.top) - rc_client.bottom;
842
+
843
+ if (!wfc->disablewindowtracking)
844
+ {
845
+ wfc->diff.x = dx;
846
+ wfc->diff.y = dy;
847
+ }
848
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_rail.c ADDED
@@ -0,0 +1,994 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ *
4
+ * Copyright 2013-2014 Marc-Andre Moreau <[email protected]>
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #include <freerdp/config.h>
20
+
21
+ #include <winpr/crt.h>
22
+ #include <freerdp/log.h>
23
+ #include <freerdp/client/rail.h>
24
+ #include <winpr/tchar.h>
25
+ #include <winpr/print.h>
26
+
27
+ #include "wf_rail.h"
28
+
29
+ #define TAG CLIENT_TAG("windows")
30
+
31
+ #define GET_X_LPARAM(lParam) ((UINT16)(lParam & 0xFFFF))
32
+ #define GET_Y_LPARAM(lParam) ((UINT16)((lParam >> 16) & 0xFFFF))
33
+
34
+ struct wf_rail_window
35
+ {
36
+ wfContext* wfc;
37
+
38
+ HWND hWnd;
39
+
40
+ DWORD dwStyle;
41
+ DWORD dwExStyle;
42
+
43
+ int x;
44
+ int y;
45
+ int width;
46
+ int height;
47
+ char* title;
48
+ };
49
+
50
+ /* RemoteApp Core Protocol Extension */
51
+
52
+ typedef struct
53
+ {
54
+ UINT32 style;
55
+ const char* name;
56
+ BOOL multi;
57
+ } WINDOW_STYLE;
58
+
59
+ static const WINDOW_STYLE WINDOW_STYLES[] = { { WS_BORDER, "WS_BORDER", FALSE },
60
+ { WS_CAPTION, "WS_CAPTION", FALSE },
61
+ { WS_CHILD, "WS_CHILD", FALSE },
62
+ { WS_CLIPCHILDREN, "WS_CLIPCHILDREN", FALSE },
63
+ { WS_CLIPSIBLINGS, "WS_CLIPSIBLINGS", FALSE },
64
+ { WS_DISABLED, "WS_DISABLED", FALSE },
65
+ { WS_DLGFRAME, "WS_DLGFRAME", FALSE },
66
+ { WS_GROUP, "WS_GROUP", FALSE },
67
+ { WS_HSCROLL, "WS_HSCROLL", FALSE },
68
+ { WS_ICONIC, "WS_ICONIC", FALSE },
69
+ { WS_MAXIMIZE, "WS_MAXIMIZE", FALSE },
70
+ { WS_MAXIMIZEBOX, "WS_MAXIMIZEBOX", FALSE },
71
+ { WS_MINIMIZE, "WS_MINIMIZE", FALSE },
72
+ { WS_MINIMIZEBOX, "WS_MINIMIZEBOX", FALSE },
73
+ { WS_OVERLAPPED, "WS_OVERLAPPED", FALSE },
74
+ { WS_OVERLAPPEDWINDOW, "WS_OVERLAPPEDWINDOW", TRUE },
75
+ { WS_POPUP, "WS_POPUP", FALSE },
76
+ { WS_POPUPWINDOW, "WS_POPUPWINDOW", TRUE },
77
+ { WS_SIZEBOX, "WS_SIZEBOX", FALSE },
78
+ { WS_SYSMENU, "WS_SYSMENU", FALSE },
79
+ { WS_TABSTOP, "WS_TABSTOP", FALSE },
80
+ { WS_THICKFRAME, "WS_THICKFRAME", FALSE },
81
+ { WS_VISIBLE, "WS_VISIBLE", FALSE } };
82
+
83
+ static const WINDOW_STYLE EXTENDED_WINDOW_STYLES[] = {
84
+ { WS_EX_ACCEPTFILES, "WS_EX_ACCEPTFILES", FALSE },
85
+ { WS_EX_APPWINDOW, "WS_EX_APPWINDOW", FALSE },
86
+ { WS_EX_CLIENTEDGE, "WS_EX_CLIENTEDGE", FALSE },
87
+ { WS_EX_COMPOSITED, "WS_EX_COMPOSITED", FALSE },
88
+ { WS_EX_CONTEXTHELP, "WS_EX_CONTEXTHELP", FALSE },
89
+ { WS_EX_CONTROLPARENT, "WS_EX_CONTROLPARENT", FALSE },
90
+ { WS_EX_DLGMODALFRAME, "WS_EX_DLGMODALFRAME", FALSE },
91
+ { WS_EX_LAYERED, "WS_EX_LAYERED", FALSE },
92
+ { WS_EX_LAYOUTRTL, "WS_EX_LAYOUTRTL", FALSE },
93
+ { WS_EX_LEFT, "WS_EX_LEFT", FALSE },
94
+ { WS_EX_LEFTSCROLLBAR, "WS_EX_LEFTSCROLLBAR", FALSE },
95
+ { WS_EX_LTRREADING, "WS_EX_LTRREADING", FALSE },
96
+ { WS_EX_MDICHILD, "WS_EX_MDICHILD", FALSE },
97
+ { WS_EX_NOACTIVATE, "WS_EX_NOACTIVATE", FALSE },
98
+ { WS_EX_NOINHERITLAYOUT, "WS_EX_NOINHERITLAYOUT", FALSE },
99
+ { WS_EX_NOPARENTNOTIFY, "WS_EX_NOPARENTNOTIFY", FALSE },
100
+ { WS_EX_OVERLAPPEDWINDOW, "WS_EX_OVERLAPPEDWINDOW", TRUE },
101
+ { WS_EX_PALETTEWINDOW, "WS_EX_PALETTEWINDOW", TRUE },
102
+ { WS_EX_RIGHT, "WS_EX_RIGHT", FALSE },
103
+ { WS_EX_RIGHTSCROLLBAR, "WS_EX_RIGHTSCROLLBAR", FALSE },
104
+ { WS_EX_RTLREADING, "WS_EX_RTLREADING", FALSE },
105
+ { WS_EX_STATICEDGE, "WS_EX_STATICEDGE", FALSE },
106
+ { WS_EX_TOOLWINDOW, "WS_EX_TOOLWINDOW", FALSE },
107
+ { WS_EX_TOPMOST, "WS_EX_TOPMOST", FALSE },
108
+ { WS_EX_TRANSPARENT, "WS_EX_TRANSPARENT", FALSE },
109
+ { WS_EX_WINDOWEDGE, "WS_EX_WINDOWEDGE", FALSE }
110
+ };
111
+
112
+ static void PrintWindowStyles(UINT32 style)
113
+ {
114
+ WLog_INFO(TAG, "\tWindow Styles:\t{");
115
+
116
+ for (size_t i = 0; i < ARRAYSIZE(WINDOW_STYLES); i++)
117
+ {
118
+ if (style & WINDOW_STYLES[i].style)
119
+ {
120
+ if (WINDOW_STYLES[i].multi)
121
+ {
122
+ if ((style & WINDOW_STYLES[i].style) != WINDOW_STYLES[i].style)
123
+ continue;
124
+ }
125
+
126
+ WLog_INFO(TAG, "\t\t%s", WINDOW_STYLES[i].name);
127
+ }
128
+ }
129
+ }
130
+
131
+ static void PrintExtendedWindowStyles(UINT32 style)
132
+ {
133
+ WLog_INFO(TAG, "\tExtended Window Styles:\t{");
134
+
135
+ for (size_t i = 0; i < ARRAYSIZE(EXTENDED_WINDOW_STYLES); i++)
136
+ {
137
+ if (style & EXTENDED_WINDOW_STYLES[i].style)
138
+ {
139
+ if (EXTENDED_WINDOW_STYLES[i].multi)
140
+ {
141
+ if ((style & EXTENDED_WINDOW_STYLES[i].style) != EXTENDED_WINDOW_STYLES[i].style)
142
+ continue;
143
+ }
144
+
145
+ WLog_INFO(TAG, "\t\t%s", EXTENDED_WINDOW_STYLES[i].name);
146
+ }
147
+ }
148
+ }
149
+
150
+ static void PrintRailWindowState(const WINDOW_ORDER_INFO* orderInfo,
151
+ const WINDOW_STATE_ORDER* windowState)
152
+ {
153
+ if (orderInfo->fieldFlags & WINDOW_ORDER_STATE_NEW)
154
+ WLog_INFO(TAG, "WindowCreate: WindowId: 0x%08X", orderInfo->windowId);
155
+ else
156
+ WLog_INFO(TAG, "WindowUpdate: WindowId: 0x%08X", orderInfo->windowId);
157
+
158
+ WLog_INFO(TAG, "{");
159
+
160
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_OWNER)
161
+ {
162
+ WLog_INFO(TAG, "\tOwnerWindowId: 0x%08X", windowState->ownerWindowId);
163
+ }
164
+
165
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_STYLE)
166
+ {
167
+ WLog_INFO(TAG, "\tStyle: 0x%08X ExtendedStyle: 0x%08X", windowState->style,
168
+ windowState->extendedStyle);
169
+ PrintWindowStyles(windowState->style);
170
+ PrintExtendedWindowStyles(windowState->extendedStyle);
171
+ }
172
+
173
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_SHOW)
174
+ {
175
+ WLog_INFO(TAG, "\tShowState: %u", windowState->showState);
176
+ }
177
+
178
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TITLE)
179
+ {
180
+ const WCHAR* str = (const WCHAR*)windowState->titleInfo.string;
181
+ char* title =
182
+ ConvertWCharNToUtf8Alloc(str, windowState->titleInfo.length / sizeof(WCHAR), NULL);
183
+ WLog_INFO(TAG, "\tTitleInfo: %s (length = %hu)", title, windowState->titleInfo.length);
184
+ free(title);
185
+ }
186
+
187
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET)
188
+ {
189
+ WLog_INFO(TAG, "\tClientOffsetX: %d ClientOffsetY: %d", windowState->clientOffsetX,
190
+ windowState->clientOffsetY);
191
+ }
192
+
193
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE)
194
+ {
195
+ WLog_INFO(TAG, "\tClientAreaWidth: %u ClientAreaHeight: %u", windowState->clientAreaWidth,
196
+ windowState->clientAreaHeight);
197
+ }
198
+
199
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RP_CONTENT)
200
+ {
201
+ WLog_INFO(TAG, "\tRPContent: %u", windowState->RPContent);
202
+ }
203
+
204
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ROOT_PARENT)
205
+ {
206
+ WLog_INFO(TAG, "\tRootParentHandle: 0x%08X", windowState->rootParentHandle);
207
+ }
208
+
209
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET)
210
+ {
211
+ WLog_INFO(TAG, "\tWindowOffsetX: %d WindowOffsetY: %d", windowState->windowOffsetX,
212
+ windowState->windowOffsetY);
213
+ }
214
+
215
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA)
216
+ {
217
+ WLog_INFO(TAG, "\tWindowClientDeltaX: %d WindowClientDeltaY: %d",
218
+ windowState->windowClientDeltaX, windowState->windowClientDeltaY);
219
+ }
220
+
221
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE)
222
+ {
223
+ WLog_INFO(TAG, "\tWindowWidth: %u WindowHeight: %u", windowState->windowWidth,
224
+ windowState->windowHeight);
225
+ }
226
+
227
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS)
228
+ {
229
+ RECTANGLE_16* rect;
230
+ WLog_INFO(TAG, "\tnumWindowRects: %u", windowState->numWindowRects);
231
+
232
+ for (UINT32 index = 0; index < windowState->numWindowRects; index++)
233
+ {
234
+ rect = &windowState->windowRects[index];
235
+ WLog_INFO(TAG, "\twindowRect[%u]: left: %hu top: %hu right: %hu bottom: %hu", index,
236
+ rect->left, rect->top, rect->right, rect->bottom);
237
+ }
238
+ }
239
+
240
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET)
241
+ {
242
+ WLog_INFO(TAG, "\tvisibileOffsetX: %d visibleOffsetY: %d", windowState->visibleOffsetX,
243
+ windowState->visibleOffsetY);
244
+ }
245
+
246
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY)
247
+ {
248
+ RECTANGLE_16* rect;
249
+ WLog_INFO(TAG, "\tnumVisibilityRects: %u", windowState->numVisibilityRects);
250
+
251
+ for (UINT32 index = 0; index < windowState->numVisibilityRects; index++)
252
+ {
253
+ rect = &windowState->visibilityRects[index];
254
+ WLog_INFO(TAG, "\tvisibilityRect[%u]: left: %hu top: %hu right: %hu bottom: %hu", index,
255
+ rect->left, rect->top, rect->right, rect->bottom);
256
+ }
257
+ }
258
+
259
+ WLog_INFO(TAG, "}");
260
+ }
261
+
262
+ static void PrintRailIconInfo(const WINDOW_ORDER_INFO* orderInfo, const ICON_INFO* iconInfo)
263
+ {
264
+ WLog_INFO(TAG, "ICON_INFO");
265
+ WLog_INFO(TAG, "{");
266
+ WLog_INFO(TAG, "\tbigIcon: %s",
267
+ (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ICON_BIG) ? "true" : "false");
268
+ WLog_INFO(TAG, "\tcacheEntry; 0x%08X", iconInfo->cacheEntry);
269
+ WLog_INFO(TAG, "\tcacheId: 0x%08X", iconInfo->cacheId);
270
+ WLog_INFO(TAG, "\tbpp: %u", iconInfo->bpp);
271
+ WLog_INFO(TAG, "\twidth: %u", iconInfo->width);
272
+ WLog_INFO(TAG, "\theight: %u", iconInfo->height);
273
+ WLog_INFO(TAG, "\tcbColorTable: %u", iconInfo->cbColorTable);
274
+ WLog_INFO(TAG, "\tcbBitsMask: %u", iconInfo->cbBitsMask);
275
+ WLog_INFO(TAG, "\tcbBitsColor: %u", iconInfo->cbBitsColor);
276
+ WLog_INFO(TAG, "\tcolorTable: %p", (void*)iconInfo->colorTable);
277
+ WLog_INFO(TAG, "\tbitsMask: %p", (void*)iconInfo->bitsMask);
278
+ WLog_INFO(TAG, "\tbitsColor: %p", (void*)iconInfo->bitsColor);
279
+ WLog_INFO(TAG, "}");
280
+ }
281
+
282
+ LRESULT CALLBACK wf_RailWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
283
+ {
284
+ HDC hDC;
285
+ int x, y;
286
+ int width;
287
+ int height;
288
+ UINT32 xPos;
289
+ UINT32 yPos;
290
+ PAINTSTRUCT ps;
291
+ UINT32 inputFlags;
292
+ wfContext* wfc = NULL;
293
+ rdpInput* input = NULL;
294
+ rdpContext* context = NULL;
295
+ wfRailWindow* railWindow;
296
+ railWindow = (wfRailWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
297
+
298
+ if (railWindow)
299
+ wfc = railWindow->wfc;
300
+
301
+ if (wfc)
302
+ context = (rdpContext*)wfc;
303
+
304
+ if (context)
305
+ input = context->input;
306
+
307
+ switch (msg)
308
+ {
309
+ case WM_PAINT:
310
+ {
311
+ if (!wfc)
312
+ return 0;
313
+
314
+ hDC = BeginPaint(hWnd, &ps);
315
+ x = ps.rcPaint.left;
316
+ y = ps.rcPaint.top;
317
+ width = ps.rcPaint.right - ps.rcPaint.left + 1;
318
+ height = ps.rcPaint.bottom - ps.rcPaint.top + 1;
319
+ BitBlt(hDC, x, y, width, height, wfc->primary->hdc, railWindow->x + x,
320
+ railWindow->y + y, SRCCOPY);
321
+ EndPaint(hWnd, &ps);
322
+ }
323
+ break;
324
+
325
+ case WM_LBUTTONDOWN:
326
+ {
327
+ if (!railWindow || !input)
328
+ return 0;
329
+
330
+ xPos = GET_X_LPARAM(lParam) + railWindow->x;
331
+ yPos = GET_Y_LPARAM(lParam) + railWindow->y;
332
+ inputFlags = PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1;
333
+
334
+ if (input)
335
+ input->MouseEvent(input, inputFlags, xPos, yPos);
336
+ }
337
+ break;
338
+
339
+ case WM_LBUTTONUP:
340
+ {
341
+ if (!railWindow || !input)
342
+ return 0;
343
+
344
+ xPos = GET_X_LPARAM(lParam) + railWindow->x;
345
+ yPos = GET_Y_LPARAM(lParam) + railWindow->y;
346
+ inputFlags = PTR_FLAGS_BUTTON1;
347
+
348
+ if (input)
349
+ input->MouseEvent(input, inputFlags, xPos, yPos);
350
+ }
351
+ break;
352
+
353
+ case WM_RBUTTONDOWN:
354
+ {
355
+ if (!railWindow || !input)
356
+ return 0;
357
+
358
+ xPos = GET_X_LPARAM(lParam) + railWindow->x;
359
+ yPos = GET_Y_LPARAM(lParam) + railWindow->y;
360
+ inputFlags = PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2;
361
+
362
+ if (input)
363
+ input->MouseEvent(input, inputFlags, xPos, yPos);
364
+ }
365
+ break;
366
+
367
+ case WM_RBUTTONUP:
368
+ {
369
+ if (!railWindow || !input)
370
+ return 0;
371
+
372
+ xPos = GET_X_LPARAM(lParam) + railWindow->x;
373
+ yPos = GET_Y_LPARAM(lParam) + railWindow->y;
374
+ inputFlags = PTR_FLAGS_BUTTON2;
375
+
376
+ if (input)
377
+ input->MouseEvent(input, inputFlags, xPos, yPos);
378
+ }
379
+ break;
380
+
381
+ case WM_MOUSEMOVE:
382
+ {
383
+ if (!railWindow || !input)
384
+ return 0;
385
+
386
+ xPos = GET_X_LPARAM(lParam) + railWindow->x;
387
+ yPos = GET_Y_LPARAM(lParam) + railWindow->y;
388
+ inputFlags = PTR_FLAGS_MOVE;
389
+
390
+ if (input)
391
+ input->MouseEvent(input, inputFlags, xPos, yPos);
392
+ }
393
+ break;
394
+
395
+ case WM_MOUSEWHEEL:
396
+ break;
397
+
398
+ case WM_CLOSE:
399
+ DestroyWindow(hWnd);
400
+ break;
401
+
402
+ case WM_DESTROY:
403
+ PostQuitMessage(0);
404
+ break;
405
+
406
+ default:
407
+ return DefWindowProc(hWnd, msg, wParam, lParam);
408
+ }
409
+
410
+ return 0;
411
+ }
412
+
413
+ #define RAIL_DISABLED_WINDOW_STYLES \
414
+ (WS_BORDER | WS_THICKFRAME | WS_DLGFRAME | WS_CAPTION | WS_OVERLAPPED | WS_VSCROLL | \
415
+ WS_HSCROLL | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)
416
+ #define RAIL_DISABLED_EXTENDED_WINDOW_STYLES \
417
+ (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_WINDOWEDGE)
418
+
419
+ static BOOL wf_rail_window_common(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
420
+ const WINDOW_STATE_ORDER* windowState)
421
+ {
422
+ wfRailWindow* railWindow = NULL;
423
+ wfContext* wfc = (wfContext*)context;
424
+ RailClientContext* rail = wfc->rail;
425
+ UINT32 fieldFlags = orderInfo->fieldFlags;
426
+ PrintRailWindowState(orderInfo, windowState);
427
+
428
+ if (fieldFlags & WINDOW_ORDER_STATE_NEW)
429
+ {
430
+ BOOL rc;
431
+ HANDLE hInstance;
432
+ WCHAR* titleW = NULL;
433
+ WNDCLASSEX wndClassEx = { 0 };
434
+ railWindow = (wfRailWindow*)calloc(1, sizeof(wfRailWindow));
435
+
436
+ if (!railWindow)
437
+ return FALSE;
438
+
439
+ railWindow->wfc = wfc;
440
+ railWindow->dwStyle = windowState->style;
441
+ railWindow->dwStyle &= ~RAIL_DISABLED_WINDOW_STYLES;
442
+ railWindow->dwExStyle = windowState->extendedStyle;
443
+ railWindow->dwExStyle &= ~RAIL_DISABLED_EXTENDED_WINDOW_STYLES;
444
+ railWindow->x = windowState->windowOffsetX;
445
+ railWindow->y = windowState->windowOffsetY;
446
+ railWindow->width = windowState->windowWidth;
447
+ railWindow->height = windowState->windowHeight;
448
+
449
+ if (fieldFlags & WINDOW_ORDER_FIELD_TITLE)
450
+ {
451
+ const WCHAR* str = (const WCHAR*)windowState->titleInfo.string;
452
+ char* title = NULL;
453
+
454
+ if (windowState->titleInfo.length == 0)
455
+ {
456
+ if (!(title = _strdup("")))
457
+ {
458
+ WLog_ERR(TAG, "failed to duplicate empty window title string");
459
+ /* error handled below */
460
+ }
461
+ }
462
+ else if (!(title = ConvertWCharNToUtf8Alloc(
463
+ str, windowState->titleInfo.length / sizeof(WCHAR), NULL)))
464
+ {
465
+ WLog_ERR(TAG, "failed to convert window title");
466
+ /* error handled below */
467
+ }
468
+
469
+ railWindow->title = title;
470
+ }
471
+ else
472
+ {
473
+ if (!(railWindow->title = _strdup("RdpRailWindow")))
474
+ WLog_ERR(TAG, "failed to duplicate default window title string");
475
+ }
476
+
477
+ if (!railWindow->title)
478
+ {
479
+ free(railWindow);
480
+ return FALSE;
481
+ }
482
+
483
+ titleW = ConvertUtf8ToWCharAlloc(railWindow->title, NULL);
484
+ hInstance = GetModuleHandle(NULL);
485
+
486
+ wndClassEx.cbSize = sizeof(WNDCLASSEX);
487
+ wndClassEx.style = 0;
488
+ wndClassEx.lpfnWndProc = wf_RailWndProc;
489
+ wndClassEx.cbClsExtra = 0;
490
+ wndClassEx.cbWndExtra = 0;
491
+ wndClassEx.hIcon = NULL;
492
+ wndClassEx.hCursor = NULL;
493
+ wndClassEx.hbrBackground = NULL;
494
+ wndClassEx.lpszMenuName = NULL;
495
+ wndClassEx.lpszClassName = _T("RdpRailWindow");
496
+ wndClassEx.hInstance = hInstance;
497
+ wndClassEx.hIconSm = NULL;
498
+ RegisterClassEx(&wndClassEx);
499
+ railWindow->hWnd = CreateWindowExW(railWindow->dwExStyle, /* dwExStyle */
500
+ _T("RdpRailWindow"), /* lpClassName */
501
+ titleW, /* lpWindowName */
502
+ railWindow->dwStyle, /* dwStyle */
503
+ railWindow->x, /* x */
504
+ railWindow->y, /* y */
505
+ railWindow->width, /* nWidth */
506
+ railWindow->height, /* nHeight */
507
+ NULL, /* hWndParent */
508
+ NULL, /* hMenu */
509
+ hInstance, /* hInstance */
510
+ NULL /* lpParam */
511
+ );
512
+
513
+ if (!railWindow->hWnd)
514
+ {
515
+ free(titleW);
516
+ free(railWindow->title);
517
+ free(railWindow);
518
+ WLog_ERR(TAG, "CreateWindowExW failed with error %" PRIu32 "", GetLastError());
519
+ return FALSE;
520
+ }
521
+
522
+ SetWindowLongPtr(railWindow->hWnd, GWLP_USERDATA, (LONG_PTR)railWindow);
523
+ rc = HashTable_Insert(wfc->railWindows, (void*)(UINT_PTR)orderInfo->windowId,
524
+ (void*)railWindow);
525
+ free(titleW);
526
+ UpdateWindow(railWindow->hWnd);
527
+ return rc;
528
+ }
529
+ else
530
+ {
531
+ railWindow = (wfRailWindow*)HashTable_GetItemValue(wfc->railWindows,
532
+ (void*)(UINT_PTR)orderInfo->windowId);
533
+ }
534
+
535
+ if (!railWindow)
536
+ return TRUE;
537
+
538
+ if ((fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) || (fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE))
539
+ {
540
+ if (fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET)
541
+ {
542
+ railWindow->x = windowState->windowOffsetX;
543
+ railWindow->y = windowState->windowOffsetY;
544
+ }
545
+
546
+ if (fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE)
547
+ {
548
+ railWindow->width = windowState->windowWidth;
549
+ railWindow->height = windowState->windowHeight;
550
+ }
551
+
552
+ SetWindowPos(railWindow->hWnd, NULL, railWindow->x, railWindow->y, railWindow->width,
553
+ railWindow->height, 0);
554
+ }
555
+
556
+ if (fieldFlags & WINDOW_ORDER_FIELD_OWNER)
557
+ {
558
+ }
559
+
560
+ if (fieldFlags & WINDOW_ORDER_FIELD_STYLE)
561
+ {
562
+ railWindow->dwStyle = windowState->style;
563
+ railWindow->dwStyle &= ~RAIL_DISABLED_WINDOW_STYLES;
564
+ railWindow->dwExStyle = windowState->extendedStyle;
565
+ railWindow->dwExStyle &= ~RAIL_DISABLED_EXTENDED_WINDOW_STYLES;
566
+ SetWindowLongPtr(railWindow->hWnd, GWL_STYLE, (LONG)railWindow->dwStyle);
567
+ SetWindowLongPtr(railWindow->hWnd, GWL_EXSTYLE, (LONG)railWindow->dwExStyle);
568
+ }
569
+
570
+ if (fieldFlags & WINDOW_ORDER_FIELD_SHOW)
571
+ {
572
+ ShowWindow(railWindow->hWnd, windowState->showState);
573
+ }
574
+
575
+ if (fieldFlags & WINDOW_ORDER_FIELD_TITLE)
576
+ {
577
+ const WCHAR* str = (const WCHAR*)windowState->titleInfo.string;
578
+ char* title = NULL;
579
+
580
+ if (windowState->titleInfo.length == 0)
581
+ {
582
+ if (!(title = _strdup("")))
583
+ {
584
+ WLog_ERR(TAG, "failed to duplicate empty window title string");
585
+ return FALSE;
586
+ }
587
+ }
588
+ else if (!(title = ConvertWCharNToUtf8Alloc(
589
+ str, windowState->titleInfo.length / sizeof(WCHAR), NULL)))
590
+ {
591
+ WLog_ERR(TAG, "failed to convert window title");
592
+ return FALSE;
593
+ }
594
+
595
+ free(railWindow->title);
596
+ railWindow->title = title;
597
+ SetWindowTextW(railWindow->hWnd, str);
598
+ }
599
+
600
+ if (fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET)
601
+ {
602
+ }
603
+
604
+ if (fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE)
605
+ {
606
+ }
607
+
608
+ if (fieldFlags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA)
609
+ {
610
+ }
611
+
612
+ if (fieldFlags & WINDOW_ORDER_FIELD_RP_CONTENT)
613
+ {
614
+ }
615
+
616
+ if (fieldFlags & WINDOW_ORDER_FIELD_ROOT_PARENT)
617
+ {
618
+ }
619
+
620
+ if (fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS)
621
+ {
622
+ HRGN hWndRect;
623
+ HRGN hWndRects;
624
+ RECTANGLE_16* rect;
625
+
626
+ if (windowState->numWindowRects > 0)
627
+ {
628
+ rect = &(windowState->windowRects[0]);
629
+ hWndRects = CreateRectRgn(rect->left, rect->top, rect->right, rect->bottom);
630
+
631
+ for (UINT32 index = 1; index < windowState->numWindowRects; index++)
632
+ {
633
+ rect = &(windowState->windowRects[index]);
634
+ hWndRect = CreateRectRgn(rect->left, rect->top, rect->right, rect->bottom);
635
+ CombineRgn(hWndRects, hWndRects, hWndRect, RGN_OR);
636
+ DeleteObject(hWndRect);
637
+ }
638
+
639
+ SetWindowRgn(railWindow->hWnd, hWndRects, TRUE);
640
+ DeleteObject(hWndRects);
641
+ }
642
+ }
643
+
644
+ if (fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET)
645
+ {
646
+ }
647
+
648
+ if (fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY)
649
+ {
650
+ }
651
+
652
+ UpdateWindow(railWindow->hWnd);
653
+ return TRUE;
654
+ }
655
+
656
+ static BOOL wf_rail_window_delete(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo)
657
+ {
658
+ wfRailWindow* railWindow = NULL;
659
+ wfContext* wfc = (wfContext*)context;
660
+ RailClientContext* rail = wfc->rail;
661
+ WLog_DBG(TAG, "RailWindowDelete");
662
+ railWindow = (wfRailWindow*)HashTable_GetItemValue(wfc->railWindows,
663
+ (void*)(UINT_PTR)orderInfo->windowId);
664
+
665
+ if (!railWindow)
666
+ return TRUE;
667
+
668
+ HashTable_Remove(wfc->railWindows, (void*)(UINT_PTR)orderInfo->windowId);
669
+ DestroyWindow(railWindow->hWnd);
670
+ free(railWindow);
671
+ return TRUE;
672
+ }
673
+
674
+ static BOOL wf_rail_window_icon(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
675
+ const WINDOW_ICON_ORDER* windowIcon)
676
+ {
677
+ HDC hDC;
678
+ int bpp;
679
+ int width;
680
+ int height;
681
+ HICON hIcon;
682
+ BOOL bigIcon;
683
+ ICONINFO iconInfo = { 0 };
684
+ BITMAPINFO bitmapInfo = { 0 };
685
+ wfRailWindow* railWindow;
686
+ BITMAPINFOHEADER* bitmapInfoHeader;
687
+ wfContext* wfc = (wfContext*)context;
688
+ RailClientContext* rail = wfc->rail;
689
+ WLog_DBG(TAG, "RailWindowIcon");
690
+ PrintRailIconInfo(orderInfo, windowIcon->iconInfo);
691
+ railWindow = (wfRailWindow*)HashTable_GetItemValue(wfc->railWindows,
692
+ (void*)(UINT_PTR)orderInfo->windowId);
693
+
694
+ if (!railWindow)
695
+ return TRUE;
696
+
697
+ bigIcon = (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ICON_BIG) ? TRUE : FALSE;
698
+ hDC = GetDC(railWindow->hWnd);
699
+ iconInfo.fIcon = TRUE;
700
+ iconInfo.xHotspot = 0;
701
+ iconInfo.yHotspot = 0;
702
+
703
+ bitmapInfoHeader = &(bitmapInfo.bmiHeader);
704
+ bpp = windowIcon->iconInfo->bpp;
705
+ width = windowIcon->iconInfo->width;
706
+ height = windowIcon->iconInfo->height;
707
+ bitmapInfoHeader->biSize = sizeof(BITMAPINFOHEADER);
708
+ bitmapInfoHeader->biWidth = width;
709
+ bitmapInfoHeader->biHeight = height;
710
+ bitmapInfoHeader->biPlanes = 1;
711
+ bitmapInfoHeader->biBitCount = bpp;
712
+ bitmapInfoHeader->biCompression = 0;
713
+ bitmapInfoHeader->biSizeImage = height * width * ((bpp + 7) / 8);
714
+ bitmapInfoHeader->biXPelsPerMeter = width;
715
+ bitmapInfoHeader->biYPelsPerMeter = height;
716
+ bitmapInfoHeader->biClrUsed = 0;
717
+ bitmapInfoHeader->biClrImportant = 0;
718
+ iconInfo.hbmMask = CreateDIBitmap(hDC, bitmapInfoHeader, CBM_INIT,
719
+ windowIcon->iconInfo->bitsMask, &bitmapInfo, DIB_RGB_COLORS);
720
+ iconInfo.hbmColor =
721
+ CreateDIBitmap(hDC, bitmapInfoHeader, CBM_INIT, windowIcon->iconInfo->bitsColor,
722
+ &bitmapInfo, DIB_RGB_COLORS);
723
+ hIcon = CreateIconIndirect(&iconInfo);
724
+
725
+ if (hIcon)
726
+ {
727
+ WPARAM wParam;
728
+ LPARAM lParam;
729
+ wParam = (WPARAM)bigIcon ? ICON_BIG : ICON_SMALL;
730
+ lParam = (LPARAM)hIcon;
731
+ SendMessage(railWindow->hWnd, WM_SETICON, wParam, lParam);
732
+ }
733
+
734
+ ReleaseDC(NULL, hDC);
735
+
736
+ if (windowIcon->iconInfo->cacheEntry != 0xFFFF)
737
+ {
738
+ /* icon should be cached */
739
+ }
740
+
741
+ return TRUE;
742
+ }
743
+
744
+ static BOOL wf_rail_window_cached_icon(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
745
+ const WINDOW_CACHED_ICON_ORDER* windowCachedIcon)
746
+ {
747
+ WLog_DBG(TAG, "RailWindowCachedIcon");
748
+ return TRUE;
749
+ }
750
+
751
+ static void wf_rail_notify_icon_common(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
752
+ const NOTIFY_ICON_STATE_ORDER* notifyIconState)
753
+ {
754
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_VERSION)
755
+ {
756
+ }
757
+
758
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_TIP)
759
+ {
760
+ }
761
+
762
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_INFO_TIP)
763
+ {
764
+ }
765
+
766
+ if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_STATE)
767
+ {
768
+ }
769
+
770
+ if (orderInfo->fieldFlags & WINDOW_ORDER_ICON)
771
+ {
772
+ const ICON_INFO* iconInfo = &(notifyIconState->icon);
773
+ PrintRailIconInfo(orderInfo, iconInfo);
774
+ }
775
+
776
+ if (orderInfo->fieldFlags & WINDOW_ORDER_CACHED_ICON)
777
+ {
778
+ }
779
+ }
780
+
781
+ static BOOL wf_rail_notify_icon_create(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
782
+ const NOTIFY_ICON_STATE_ORDER* notifyIconState)
783
+ {
784
+ wfContext* wfc = (wfContext*)context;
785
+ RailClientContext* rail = wfc->rail;
786
+ WLog_DBG(TAG, "RailNotifyIconCreate");
787
+ wf_rail_notify_icon_common(context, orderInfo, notifyIconState);
788
+ return TRUE;
789
+ }
790
+
791
+ static BOOL wf_rail_notify_icon_update(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
792
+ const NOTIFY_ICON_STATE_ORDER* notifyIconState)
793
+ {
794
+ wfContext* wfc = (wfContext*)context;
795
+ RailClientContext* rail = wfc->rail;
796
+ WLog_DBG(TAG, "RailNotifyIconUpdate");
797
+ wf_rail_notify_icon_common(context, orderInfo, notifyIconState);
798
+ return TRUE;
799
+ }
800
+
801
+ static BOOL wf_rail_notify_icon_delete(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo)
802
+ {
803
+ wfContext* wfc = (wfContext*)context;
804
+ RailClientContext* rail = wfc->rail;
805
+ WLog_DBG(TAG, "RailNotifyIconDelete");
806
+ return TRUE;
807
+ }
808
+
809
+ static BOOL wf_rail_monitored_desktop(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
810
+ const MONITORED_DESKTOP_ORDER* monitoredDesktop)
811
+ {
812
+ wfContext* wfc = (wfContext*)context;
813
+ RailClientContext* rail = wfc->rail;
814
+ WLog_DBG(TAG, "RailMonitorDesktop");
815
+ return TRUE;
816
+ }
817
+
818
+ static BOOL wf_rail_non_monitored_desktop(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo)
819
+ {
820
+ wfContext* wfc = (wfContext*)context;
821
+ RailClientContext* rail = wfc->rail;
822
+ WLog_DBG(TAG, "RailNonMonitorDesktop");
823
+ return TRUE;
824
+ }
825
+
826
+ void wf_rail_register_update_callbacks(rdpUpdate* update)
827
+ {
828
+ rdpWindowUpdate* window = update->window;
829
+ window->WindowCreate = wf_rail_window_common;
830
+ window->WindowUpdate = wf_rail_window_common;
831
+ window->WindowDelete = wf_rail_window_delete;
832
+ window->WindowIcon = wf_rail_window_icon;
833
+ window->WindowCachedIcon = wf_rail_window_cached_icon;
834
+ window->NotifyIconCreate = wf_rail_notify_icon_create;
835
+ window->NotifyIconUpdate = wf_rail_notify_icon_update;
836
+ window->NotifyIconDelete = wf_rail_notify_icon_delete;
837
+ window->MonitoredDesktop = wf_rail_monitored_desktop;
838
+ window->NonMonitoredDesktop = wf_rail_non_monitored_desktop;
839
+ }
840
+
841
+ /* RemoteApp Virtual Channel Extension */
842
+
843
+ /**
844
+ * Function description
845
+ *
846
+ * @return 0 on success, otherwise a Win32 error code
847
+ */
848
+ static UINT wf_rail_server_execute_result(RailClientContext* context,
849
+ const RAIL_EXEC_RESULT_ORDER* execResult)
850
+ {
851
+ WLog_DBG(TAG, "RailServerExecuteResult: 0x%08X", execResult->rawResult);
852
+ return CHANNEL_RC_OK;
853
+ }
854
+
855
+ /**
856
+ * Function description
857
+ *
858
+ * @return 0 on success, otherwise a Win32 error code
859
+ */
860
+ static UINT wf_rail_server_system_param(RailClientContext* context,
861
+ const RAIL_SYSPARAM_ORDER* sysparam)
862
+ {
863
+ return CHANNEL_RC_OK;
864
+ }
865
+
866
+ /**
867
+ * Function description
868
+ *
869
+ * @return 0 on success, otherwise a Win32 error code
870
+ */
871
+ static UINT wf_rail_server_handshake(RailClientContext* context,
872
+ const RAIL_HANDSHAKE_ORDER* handshake)
873
+ {
874
+ return client_rail_server_start_cmd(context);
875
+ }
876
+
877
+ /**
878
+ * Function description
879
+ *
880
+ * @return 0 on success, otherwise a Win32 error code
881
+ */
882
+ static UINT wf_rail_server_handshake_ex(RailClientContext* context,
883
+ const RAIL_HANDSHAKE_EX_ORDER* handshakeEx)
884
+ {
885
+ return client_rail_server_start_cmd(context);
886
+ }
887
+
888
+ /**
889
+ * Function description
890
+ *
891
+ * @return 0 on success, otherwise a Win32 error code
892
+ */
893
+ static UINT wf_rail_server_local_move_size(RailClientContext* context,
894
+ const RAIL_LOCALMOVESIZE_ORDER* localMoveSize)
895
+ {
896
+ return CHANNEL_RC_OK;
897
+ }
898
+
899
+ /**
900
+ * Function description
901
+ *
902
+ * @return 0 on success, otherwise a Win32 error code
903
+ */
904
+ static UINT wf_rail_server_min_max_info(RailClientContext* context,
905
+ const RAIL_MINMAXINFO_ORDER* minMaxInfo)
906
+ {
907
+ return CHANNEL_RC_OK;
908
+ }
909
+
910
+ /**
911
+ * Function description
912
+ *
913
+ * @return 0 on success, otherwise a Win32 error code
914
+ */
915
+ static UINT wf_rail_server_language_bar_info(RailClientContext* context,
916
+ const RAIL_LANGBAR_INFO_ORDER* langBarInfo)
917
+ {
918
+ return CHANNEL_RC_OK;
919
+ }
920
+
921
+ /**
922
+ * Function description
923
+ *
924
+ * @return 0 on success, otherwise a Win32 error code
925
+ */
926
+ static UINT wf_rail_server_get_appid_response(RailClientContext* context,
927
+ const RAIL_GET_APPID_RESP_ORDER* getAppIdResp)
928
+ {
929
+ return CHANNEL_RC_OK;
930
+ }
931
+
932
+ void wf_rail_invalidate_region(wfContext* wfc, REGION16* invalidRegion)
933
+ {
934
+ RECT updateRect;
935
+ RECTANGLE_16 windowRect;
936
+ ULONG_PTR* pKeys = NULL;
937
+ wfRailWindow* railWindow;
938
+ const RECTANGLE_16* extents;
939
+ REGION16 windowInvalidRegion;
940
+ region16_init(&windowInvalidRegion);
941
+ size_t count = HashTable_GetKeys(wfc->railWindows, &pKeys);
942
+
943
+ for (size_t index = 0; index < count; index++)
944
+ {
945
+ railWindow = (wfRailWindow*)HashTable_GetItemValue(wfc->railWindows, (void*)pKeys[index]);
946
+
947
+ if (railWindow)
948
+ {
949
+ windowRect.left = railWindow->x;
950
+ windowRect.top = railWindow->y;
951
+ windowRect.right = railWindow->x + railWindow->width;
952
+ windowRect.bottom = railWindow->y + railWindow->height;
953
+ region16_clear(&windowInvalidRegion);
954
+ region16_intersect_rect(&windowInvalidRegion, invalidRegion, &windowRect);
955
+
956
+ if (!region16_is_empty(&windowInvalidRegion))
957
+ {
958
+ extents = region16_extents(&windowInvalidRegion);
959
+ updateRect.left = extents->left - railWindow->x;
960
+ updateRect.top = extents->top - railWindow->y;
961
+ updateRect.right = extents->right - railWindow->x;
962
+ updateRect.bottom = extents->bottom - railWindow->y;
963
+ InvalidateRect(railWindow->hWnd, &updateRect, FALSE);
964
+ }
965
+ }
966
+ }
967
+
968
+ region16_uninit(&windowInvalidRegion);
969
+ }
970
+
971
+ BOOL wf_rail_init(wfContext* wfc, RailClientContext* rail)
972
+ {
973
+ rdpContext* context = (rdpContext*)wfc;
974
+ wfc->rail = rail;
975
+ rail->custom = (void*)wfc;
976
+ rail->ServerExecuteResult = wf_rail_server_execute_result;
977
+ rail->ServerSystemParam = wf_rail_server_system_param;
978
+ rail->ServerHandshake = wf_rail_server_handshake;
979
+ rail->ServerHandshakeEx = wf_rail_server_handshake_ex;
980
+ rail->ServerLocalMoveSize = wf_rail_server_local_move_size;
981
+ rail->ServerMinMaxInfo = wf_rail_server_min_max_info;
982
+ rail->ServerLanguageBarInfo = wf_rail_server_language_bar_info;
983
+ rail->ServerGetAppIdResponse = wf_rail_server_get_appid_response;
984
+ wf_rail_register_update_callbacks(context->update);
985
+ wfc->railWindows = HashTable_New(TRUE);
986
+ return (wfc->railWindows != NULL);
987
+ }
988
+
989
+ void wf_rail_uninit(wfContext* wfc, RailClientContext* rail)
990
+ {
991
+ wfc->rail = NULL;
992
+ rail->custom = NULL;
993
+ HashTable_Free(wfc->railWindows);
994
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_rail.h ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ *
4
+ * Copyright 2013-2014 Marc-Andre Moreau <[email protected]>
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #ifndef FREERDP_CLIENT_WIN_RAIL_H
20
+ #define FREERDP_CLIENT_WIN_RAIL_H
21
+
22
+ typedef struct wf_rail_window wfRailWindow;
23
+
24
+ #include "wf_client.h"
25
+
26
+ #include <freerdp/client/rail.h>
27
+
28
+ BOOL wf_rail_init(wfContext* wfc, RailClientContext* rail);
29
+ void wf_rail_uninit(wfContext* wfc, RailClientContext* rail);
30
+
31
+ void wf_rail_invalidate_region(wfContext* wfc, REGION16* invalidRegion);
32
+
33
+ #endif /* FREERDP_CLIENT_WIN_RAIL_H */
local-test-freerdp-delta-01/afc-freerdp/client/freerdp-client.pc.in ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ prefix=@PKG_CONFIG_INSTALL_PREFIX@
2
+ exec_prefix=${prefix}
3
+ libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
4
+ includedir=${prefix}/@FREERDP_INCLUDE_DIR@
5
+ libs=-lfreerdp-client@FREERDP_API_VERSION@
6
+
7
+ Name: FreeRDP client
8
+ Description: FreeRDP: A Remote Desktop Protocol Implementation
9
+ URL: http://www.freerdp.com/
10
+ Version: @FREERDP_VERSION@
11
+ Requires:
12
+ Requires.private: @WINPR_PKG_CONFIG_FILENAME@ freerdp@FREERDP_VERSION_MAJOR@
13
+ Libs: -L${libdir} ${libs}
14
+ Libs.private: -ldl -lpthread @FREERDP_CLIENT_PC_PRIVATE_LIBS@
15
+ Cflags: -I${includedir}
local-test-freerdp-delta-01/afc-freerdp/client/iOS/AppDelegate.h ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ App delegate
3
+
4
+ Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5
+
6
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7
+ If a copy of the MPL was not distributed with this file, You can obtain one at
8
+ http://mozilla.org/MPL/2.0/.
9
+ */
10
+
11
+ #import <UIKit/UIKit.h>
12
+
13
+ @class MainTabBarController;
14
+
15
+ @interface AppDelegate : NSObject <UIApplicationDelegate>
16
+ {
17
+
18
+ MainTabBarController *_tabBarController;
19
+ }
20
+
21
+ @property(nonatomic, retain) IBOutlet UIWindow *window;
22
+ @property(nonatomic, retain) IBOutlet MainTabBarController *tabBarController;
23
+
24
+ @end
local-test-freerdp-delta-01/afc-freerdp/client/iOS/AppDelegate.m ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ App delegate
3
+
4
+ Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5
+
6
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7
+ If a copy of the MPL was not distributed with this file, You can obtain one at
8
+ http://mozilla.org/MPL/2.0/.
9
+ */
10
+
11
+ #import "AppDelegate.h"
12
+
13
+ #import "AboutController.h"
14
+ #import "HelpController.h"
15
+ #import "BookmarkListController.h"
16
+ #import "AppSettingsController.h"
17
+ #import "MainTabBarController.h"
18
+ #import "Utils.h"
19
+
20
+ @implementation AppDelegate
21
+
22
+ @synthesize window = _window, tabBarController = _tabBarController;
23
+
24
+ - (BOOL)application:(UIApplication *)application
25
+ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
26
+ {
27
+ // Set default values for most NSUserDefaults
28
+ [[NSUserDefaults standardUserDefaults]
29
+ registerDefaults:[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]
30
+ pathForResource:@"Defaults"
31
+ ofType:@"plist"]]];
32
+
33
+ // init global settings
34
+ SetSwapMouseButtonsFlag(
35
+ [[NSUserDefaults standardUserDefaults] boolForKey:@"ui.swap_mouse_buttons"]);
36
+ SetInvertScrollingFlag(
37
+ [[NSUserDefaults standardUserDefaults] boolForKey:@"ui.invert_scrolling"]);
38
+
39
+ // create bookmark view and navigation controller
40
+ BookmarkListController *bookmarkListController =
41
+ [[[BookmarkListController alloc] initWithNibName:@"BookmarkListView"
42
+ bundle:nil] autorelease];
43
+ UINavigationController *bookmarkNavigationController = [[[UINavigationController alloc]
44
+ initWithRootViewController:bookmarkListController] autorelease];
45
+
46
+ // create app settings view and navigation controller
47
+ AppSettingsController *appSettingsController =
48
+ [[[AppSettingsController alloc] initWithStyle:UITableViewStyleGrouped] autorelease];
49
+ UINavigationController *appSettingsNavigationController = [[[UINavigationController alloc]
50
+ initWithRootViewController:appSettingsController] autorelease];
51
+
52
+ // create help view controller
53
+ HelpController *helpViewController = [[[HelpController alloc] initWithNibName:nil
54
+ bundle:nil] autorelease];
55
+
56
+ // create about view controller
57
+ AboutController *aboutViewController =
58
+ [[[AboutController alloc] initWithNibName:nil bundle:nil] autorelease];
59
+
60
+ // add tab-bar controller to the main window and display everything
61
+ NSArray *tabItems =
62
+ [NSArray arrayWithObjects:bookmarkNavigationController, appSettingsNavigationController,
63
+ helpViewController, aboutViewController, nil];
64
+ [_tabBarController setViewControllers:tabItems];
65
+ if ([_window respondsToSelector:@selector(setRootViewController:)])
66
+ [_window setRootViewController:_tabBarController];
67
+ else
68
+ [_window addSubview:[_tabBarController view]];
69
+ [_window makeKeyAndVisible];
70
+
71
+ return YES;
72
+ }
73
+
74
+ - (void)applicationWillResignActive:(UIApplication *)application
75
+ {
76
+ /*
77
+ Sent when the application is about to move from active to inactive state. This can occur for
78
+ certain types of temporary interruptions (such as an incoming phone call or SMS message) or
79
+ when the user quits the application and it begins the transition to the background state. Use
80
+ this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates.
81
+ Games should use this method to pause the game.
82
+ */
83
+ }
84
+
85
+ - (void)applicationDidEnterBackground:(UIApplication *)application
86
+ {
87
+ /*
88
+ Use this method to release shared resources, save user data, invalidate timers, and store
89
+ enough application state information to restore your application to its current state in case
90
+ it is terminated later. If your application supports background execution, this method is
91
+ called instead of applicationWillTerminate: when the user quits.
92
+ */
93
+ }
94
+
95
+ - (void)applicationWillEnterForeground:(UIApplication *)application
96
+ {
97
+ /*
98
+ Called as part of the transition from the background to the inactive state; here you can undo
99
+ many of the changes made on entering the background.
100
+ */
101
+ // cancel disconnect timer
102
+ }
103
+
104
+ - (void)applicationDidBecomeActive:(UIApplication *)application
105
+ {
106
+ /*
107
+ Restart any tasks that were paused (or not yet started) while the application was inactive. If
108
+ the application was previously in the background, optionally refresh the user interface.
109
+ */
110
+ }
111
+
112
+ - (void)applicationWillTerminate:(UIApplication *)application
113
+ {
114
+ /*
115
+ Called when the application is about to terminate.
116
+ Save data if appropriate.
117
+ See also applicationDidEnterBackground:.
118
+ */
119
+ }
120
+
121
+ - (void)dealloc
122
+ {
123
+ [_window release];
124
+ [super dealloc];
125
+ }
126
+
127
+ @end
local-test-freerdp-delta-01/afc-freerdp/client/iOS/CMakeLists.txt ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FreeRDP: A Remote Desktop Protocol Implementation
2
+ # FreeRDP X11 Client
3
+ #
4
+ # Copyright 2012 Marc-Andre Moreau <[email protected]>
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ cmake_minimum_required(VERSION 3.13)
19
+
20
+ if(NOT FREERDP_DEFAULT_PROJECT_VERSION)
21
+ set(FREERDP_DEFAULT_PROJECT_VERSION "1.0.0.0")
22
+ endif()
23
+
24
+ project(iFreeRDP VERSION ${FREERDP_DEFAULT_PROJECT_VERSION})
25
+
26
+ message("project ${PROJECT_NAME} is using version ${PROJECT_VERSION}")
27
+
28
+ list(APPEND CMAKE_MODULE_PATH ${PROJECT_CURRENT_SOURCE_DIR}/../../cmake/)
29
+ include(CommonConfigOptions)
30
+
31
+ set(MODULE_NAME "iFreeRDP")
32
+ set(MODULE_PREFIX "IFREERDP_CLIENT")
33
+ set(APP_TYPE MACOSX_BUNDLE)
34
+
35
+ set(IOS_CLIENT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
36
+ set(IOS_CLIENT_ADDITIONS_DIR ${IOS_CLIENT_DIR}/Additions)
37
+ set(IOS_CLIENT_CONTROLLERS_DIR ${IOS_CLIENT_DIR}/Controllers)
38
+ set(IOS_CLIENT_FREERDP_DIR ${IOS_CLIENT_DIR}/FreeRDP)
39
+ set(IOS_CLIENT_MISC_DIR ${IOS_CLIENT_DIR}/Misc)
40
+ set(IOS_CLIENT_MODELS_DIR ${IOS_CLIENT_DIR}/Models)
41
+ set(IOS_CLIENT_VIEWS_DIR ${IOS_CLIENT_DIR}/Views)
42
+ set(IOS_CLIENT_RESOURCES_DIR ${IOS_CLIENT_DIR}/Resources)
43
+
44
+ include_directories(SYSTEM ${IOS_CLIENT_DIR})
45
+ include_directories(SYSTEM ${IOS_CLIENT_ADDITIONS_DIR})
46
+ include_directories(SYSTEM ${IOS_CLIENT_CONTROLLERS_DIR})
47
+ include_directories(SYSTEM ${IOS_CLIENT_FREERDP_DIR})
48
+ include_directories(SYSTEM ${IOS_CLIENT_MISC_DIR})
49
+ include_directories(SYSTEM ${IOS_CLIENT_MODELS_DIR})
50
+ include_directories(SYSTEM ${IOS_CLIENT_VIEWS_DIR})
51
+ include_directories(SYSTEM ${OPENSSL_INCLUDE_DIR})
52
+
53
+ # Add sources
54
+ set(${MODULE_PREFIX}_SRCS AppDelegate.m AppDelegate.h main.m)
55
+
56
+ file(GLOB IOS_CLIENT_ADDITIONS_SRCS ${IOS_CLIENT_ADDITIONS_DIR}/*.m)
57
+ file(GLOB IOS_CLIENT_ADDITIONS_HDRS ${IOS_CLIENT_ADDITIONS_DIR}/*.h)
58
+
59
+ file(GLOB IOS_CLIENT_CONTROLLERS_SRCS ${IOS_CLIENT_CONTROLLERS_DIR}/*.m)
60
+ file(GLOB IOS_CLIENT_CONTROLLERS_HDRS ${IOS_CLIENT_CONTROLLERS_DIR}/*.h)
61
+
62
+ file(GLOB IOS_CLIENT_FREERDP_SRCS ${IOS_CLIENT_FREERDP_DIR}/*.m)
63
+ file(GLOB IOS_CLIENT_FREERDP_HDRS ${IOS_CLIENT_FREERDP_DIR}/*.h)
64
+
65
+ file(GLOB IOS_CLIENT_MISC_SRCS ${IOS_CLIENT_MISC_DIR}/*.m)
66
+ file(GLOB IOS_CLIENT_MISC_HDRS ${IOS_CLIENT_MISC_DIR}/*.h)
67
+
68
+ file(GLOB IOS_CLIENT_MODELS_SRCS ${IOS_CLIENT_MODELS_DIR}/*.m)
69
+ file(GLOB IOS_CLIENT_MODELS_HDRS ${IOS_CLIENT_MODELS_DIR}/*.h)
70
+
71
+ file(GLOB IOS_CLIENT_VIEWS_SRCS ${IOS_CLIENT_VIEWS_DIR}/*.m)
72
+ file(GLOB IOS_CLIENT_VIEWS_HDRS ${IOS_CLIENT_VIEWS_DIR}/*.h)
73
+
74
+ # add resources
75
+ file(GLOB IOS_CLIENT_RESOURCES_XIBS ${IOS_CLIENT_RESOURCES_DIR}/*.xib)
76
+ file(GLOB IOS_CLIENT_RESOURCES_PNGS ${IOS_CLIENT_RESOURCES_DIR}/*.png)
77
+
78
+ # Specify source grouping
79
+ source_group(Additions FILES ${IOS_CLIENT_ADDITIONS_SRCS} ${IOS_CLIENT_ADDITIONS_HDRS})
80
+ source_group(Controllers FILES ${IOS_CLIENT_CONTROLLERS_SRCS} ${IOS_CLIENT_CONTROLLERS_HDRS})
81
+ source_group(FreeRDP FILES ${IOS_CLIENT_FREERDP_SRCS} ${IOS_CLIENT_FREERDP_HDRS})
82
+ source_group(Misc FILES ${IOS_CLIENT_MISC_SRCS} ${IOS_CLIENT_MISC_HDRS})
83
+ source_group(Models FILES ${IOS_CLIENT_MODELS_SRCS} ${IOS_CLIENT_MODELS_HDRS})
84
+ source_group(Views FILES ${IOS_CLIENT_RESOURCES_XIBS} ${IOS_CLIENT_VIEWS_SRCS} ${IOS_CLIENT_VIEWS_HDRS})
85
+ source_group(
86
+ Resources FILES ${IOS_CLIENT_RESOURCES_PNGS} ${IOS_CLIENT_RESOURCES_DIR}/about_page
87
+ ${IOS_CLIENT_RESOURCES_DIR}/help_page ${IOS_CLIENT_RESOURCES_DIR}/en.lproj
88
+ )
89
+
90
+ # import libraries
91
+ find_library(FOUNDATION_FRAMEWORK Foundation)
92
+ find_library(COREGRAPHICS_FRAMEWORK CoreGraphics)
93
+ find_library(SECURITY_FRAMEWORK Security)
94
+ find_library(UIKIT_FRAMEWORK UIKit)
95
+ find_library(SYSTEMCONFIGURATION_FRAMEWORK SystemConfiguration)
96
+
97
+ mark_as_advanced(
98
+ FOUNDATION_FRAMEWORK COREGRAPHICS_FRAMEWORK SECURITY_FRAMEWORK UIKIT_FRAMEWORK SYSTEMCONFIGURATION_FRAMEWORK
99
+ )
100
+ set(EXTRA_LIBS ${FOUNDATION_FRAMEWORK} ${COREGRAPHICS_FRAMEWORK} ${SECURITY_FRAMEWORK} ${UIKIT_FRAMEWORK}
101
+ ${SYSTEMCONFIGURATION_FRAMEWORK}
102
+ )
103
+
104
+ set(${MODULE_NAME}_RESOURCES ${IOS_CLIENT_RESOURCES_XIBS})
105
+ set(${MODULE_NAME}_RESOURCES ${${MODULE_NAME}_RESOURCES} ${IOS_CLIENT_RESOURCES_PNGS})
106
+ set(${MODULE_NAME}_RESOURCES ${${MODULE_NAME}_RESOURCES} ${IOS_CLIENT_RESOURCES_DIR}/about_page
107
+ ${IOS_CLIENT_RESOURCES_DIR}/help_page ${IOS_CLIENT_RESOURCES_DIR}/en.lproj
108
+ )
109
+ set(${MODULE_NAME}_RESOURCES ${${MODULE_NAME}_RESOURCES} ${IOS_CLIENT_DIR}/Defaults.plist)
110
+
111
+ add_executable(
112
+ ${MODULE_NAME}
113
+ ${APP_TYPE}
114
+ ${${MODULE_PREFIX}_SRCS}
115
+ ${IOS_CLIENT_ADDITIONS_SRCS}
116
+ ${IOS_CLIENT_ADDITIONS_HDRS}
117
+ ${IOS_CLIENT_CONTROLLERS_SRCS}
118
+ ${IOS_CLIENT_CONTROLLERS_HDRS}
119
+ ${IOS_CLIENT_FREERDP_SRCS}
120
+ ${IOS_CLIENT_FREERDP_HDRS}
121
+ ${IOS_CLIENT_MISC_SRCS}
122
+ ${IOS_CLIENT_MISC_HDRS}
123
+ ${IOS_CLIENT_MODELS_SRCS}
124
+ ${IOS_CLIENT_MODELS_HDRS}
125
+ ${IOS_CLIENT_VIEWS_SRCS}
126
+ ${IOS_CLIENT_VIEWS_HDRS}
127
+ ${${MODULE_NAME}_RESOURCES}
128
+ )
129
+
130
+ if(WITH_BINARY_VERSIONING)
131
+ set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME "${MODULE_NAME}${PROJECT_VERSION_MAJOR}")
132
+ endif()
133
+ set_target_properties(${MODULE_NAME} PROPERTIES RESOURCE "${${MODULE_NAME}_RESOURCES}")
134
+
135
+ set(EXECUTABLE_NAME "\${EXECUTABLE_NAME}")
136
+
137
+ set_target_properties(${MODULE_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${IOS_CLIENT_DIR}/iFreeRDP.plist)
138
+ set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "${IOS_TARGET_SDK}")
139
+ set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "gnu++0x")
140
+ set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
141
+ set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC NO)
142
+ set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_GCC_C_LANGUAGE_STANDARD "gnu99")
143
+ set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2")
144
+ set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_COMBINE_HIDPI_IMAGES "NO")
145
+ set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_SKIP_INSTALL NO)
146
+ set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_INSTALL_PATH "/Applications")
147
+ set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS YES)
148
+ if(CODE_SIGN_IDENTITY)
149
+ set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${CODE_SIGN_IDENTITY}")
150
+ endif()
151
+
152
+ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${EXTRA_LIBS})
153
+
154
+ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp-client)
155
+
156
+ set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp)
157
+
158
+ target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
159
+
160
+ set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Client/iOS")
local-test-freerdp-delta-01/afc-freerdp/client/iOS/Defaults.plist ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>TSXDefaultComputerBookmarkSettings</key>
6
+ <dict>
7
+ <key>hostname</key>
8
+ <string></string>
9
+ <key>port</key>
10
+ <integer>3389</integer>
11
+ <key>screen_resolution_type</key>
12
+ <integer>1</integer>
13
+ <key>width</key>
14
+ <integer>0</integer>
15
+ <key>height</key>
16
+ <integer>0</integer>
17
+ <key>colors</key>
18
+ <integer>16</integer>
19
+ <key>perf_font_smoothing</key>
20
+ <false/>
21
+ <key>perf_menu_animation</key>
22
+ <false/>
23
+ <key>perf_show_desktop</key>
24
+ <false/>
25
+ <key>perf_window_dragging</key>
26
+ <false/>
27
+ <key>perf_windows_themes</key>
28
+ <false/>
29
+ <key>perf_remotefx</key>
30
+ <false/>
31
+ <key>perf_gfx</key>
32
+ <false/>
33
+ <key>perf_h264</key>
34
+ <false/>
35
+ <key>perf_desktop_composition</key>
36
+ <false/>
37
+ <key>enable_3g_settings</key>
38
+ <false/>
39
+ <key>settings_3g</key>
40
+ <dict>
41
+ <key>screen_resolution_type</key>
42
+ <integer>0</integer>
43
+ <key>width</key>
44
+ <integer>800</integer>
45
+ <key>height</key>
46
+ <integer>600</integer>
47
+ <key>colors</key>
48
+ <integer>16</integer>
49
+ <key>perf_remotefx</key>
50
+ <false/>
51
+ <key>perf_gfx</key>
52
+ <false/>
53
+ <key>perf_h264</key>
54
+ <false/>
55
+ <key>perf_desktop_composition</key>
56
+ <false/>
57
+ <key>perf_windows_themes</key>
58
+ <false/>
59
+ <key>perf_window_dragging</key>
60
+ <false/>
61
+ <key>perf_show_desktop</key>
62
+ <false/>
63
+ <key>perf_menu_animation</key>
64
+ <false/>
65
+ <key>perf_font_smoothing</key>
66
+ <false/>
67
+ </dict>
68
+ <key>security</key>
69
+ <integer>0</integer>
70
+ <key>remote_program</key>
71
+ <string></string>
72
+ <key>working_dir</key>
73
+ <string></string>
74
+ <key>console</key>
75
+ <false/>
76
+ <key>enable_tsg_settings</key>
77
+ <false/>
78
+ <key>tsg_hostname</key>
79
+ <string></string>
80
+ <key>tsg_port</key>
81
+ <integer>443</integer>
82
+ <key>tsg_username</key>
83
+ <string></string>
84
+ <key>tsg_password</key>
85
+ <string></string>
86
+ <key>tsg_domain</key>
87
+ <string></string>
88
+ </dict>
89
+ <key>ui.auto_scroll_touchpointer</key>
90
+ <true/>
91
+ </dict>
92
+ </plist>
local-test-freerdp-delta-01/afc-freerdp/client/iOS/ModuleOptions.cmake ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ set(FREERDP_CLIENT_NAME "ifreerdp")
2
+ set(FREERDP_CLIENT_PLATFORM "iOS")
3
+ set(FREERDP_CLIENT_VENDOR "FreeRDP")
local-test-freerdp-delta-01/afc-freerdp/client/iOS/iFreeRDP-Prefix.pch ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ PCH
3
+
4
+ Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5
+
6
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7
+ If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+ //
11
+ // Prefix header for all source files of the 'iFreeRDP' target in the 'iFreeRDP' project
12
+ //
13
+
14
+ #import <Availability.h>
15
+
16
+ #ifndef __IPHONE_3_0
17
+ #warning "This project uses features only available in iPhone SDK 3.0 and later."
18
+ #endif
19
+
20
+ #ifdef __OBJC__
21
+ #import <UIKit/UIKit.h>
22
+ #import <Foundation/Foundation.h>
23
+ #endif
local-test-freerdp-delta-01/afc-freerdp/client/iOS/iFreeRDP.plist ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>English</string>
7
+ <key>CFBundleDisplayName</key>
8
+ <string>iFreeRDP</string>
9
+ <key>CFBundleExecutable</key>
10
+ <string>${EXECUTABLE_NAME}</string>
11
+ <key>CFBundleIconFiles</key>
12
+ <array>
13
+ <string>Icon.png</string>
14
+ <string>Icon-72.png</string>
15
+ <string>[email protected]</string>
16
+ <string>[email protected]</string>
17
+ </array>
18
+ <key>CFBundleIdentifier</key>
19
+ <string>com.freerdp.ifreerdp</string>
20
+ <key>CFBundleInfoDictionaryVersion</key>
21
+ <string>6.0</string>
22
+ <key>CFBundleName</key>
23
+ <string>${PRODUCT_NAME}</string>
24
+ <key>CFBundlePackageType</key>
25
+ <string>APPL</string>
26
+ <key>CFBundleShortVersionString</key>
27
+ <string>1.0.1</string>
28
+ <key>CFBundleSignature</key>
29
+ <string>????</string>
30
+ <key>CFBundleVersion</key>
31
+ <string>1</string>
32
+ <key>LSRequiresIPhoneOS</key>
33
+ <true/>
34
+ <key>NSMainNibFile</key>
35
+ <string>MainWindow</string>
36
+ <key>UIPrerenderedIcon</key>
37
+ <true/>
38
+ <key>UISupportedInterfaceOrientations</key>
39
+ <array>
40
+ <string>UIInterfaceOrientationPortrait</string>
41
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
42
+ <string>UIInterfaceOrientationLandscapeLeft</string>
43
+ <string>UIInterfaceOrientationLandscapeRight</string>
44
+ </array>
45
+ <key>UISupportedInterfaceOrientations~ipad</key>
46
+ <array>
47
+ <string>UIInterfaceOrientationPortrait</string>
48
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
49
+ <string>UIInterfaceOrientationLandscapeLeft</string>
50
+ <string>UIInterfaceOrientationLandscapeRight</string>
51
+ </array>
52
+ </dict>
53
+ </plist>