Commit Graph

144 Commits

Author SHA1 Message Date
Frediano Ziglio
8512940e53 fix format string for Visual Studio
The "z" size specifier is not supported by Visual Studio.
Cast to unsigned long and use "l" specifier as the type has
enough precision for this vector.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-07-24 17:18:23 +01:00
Uri Lublin
64f771fef1 event_dispatcher: vd_printf calls -- remove __func__
vd_printf adds __FUNCTION__

Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-07-14 11:16:48 +01:00
Uri Lublin
32bb5cbeb0 clipboard: log format used
Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-07-14 11:16:42 +01:00
kunming.xie
f80ee415c1 Fix hdesk handle leak in vdagent
Signed-off-by: kunming.xie <kunming.xie@hotmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-05-23 16:35:04 +01:00
Jakub Janků
3b1d9ab0a0 Use sprintf_s instead of sprintf to not crash
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-05-18 11:03:55 +01:00
Frediano Ziglio
241425b7da Support file transfer for existing files
Previously, if the user attempted to transfer a file that had the same
name as a file that already exists on the guest, we would just fail the
transfer. This patch tries to match the behavior of the linux vdagent
where we try to append an integer onto the name of the new file to make
it unique. For example, if you tried to transfer 'file.doc' to the guest
and that file already existed, it would try to create 'file (1).doc'
instead. If that also failed, it would attempt 'file (2).doc', etc, up
to 63.

Resolves: rhbz#1410181
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-05-02 14:49:36 -05:00
Jonathon Jongsma
a2b4da90a1 Don't exit vdagent when a client disconnects
Previously, when a client disconnects, the vdagent executable exited.
The agent was restarted immediately in order to be ready for the next
client to reconnect.

This is generally fine, but there are certain situations
where it causes issues. For example, if client A is connected to a guest
and client B connects to the same guest, client A will be forcibly
disconnected and causes the the vdagent to restart. This scenario is
racy because the agent can take some time to exit and restart. Client B
may think that the agent is connected at startup and may send agent
messages to the guest.  At some point the server will recieve
notification that the agent has exited and send an AGENT_DISCONNECTED
message to client B. After the agent has been fully restarted, an
AGENT_CONNECTED message will be sent to the client, but any messages
sent between client connection and the AGENT_DISCONNECTED message will
be lost. This causes problems especially with fullscreen mode in
virt-viewer.

The solution is to not exit and restart the agent when a client
disconnects. This is how the linux vdagent behaves. Instead, we simply
cancel all ongoing file transfers and reset the clipboard when a client
is disconnected.

Fixes: rhbz#1064495
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2017-04-05 10:30:00 -05:00
Frediano Ziglio
4fbd7b485e Move common resource code to a common file
Allows to reuse code. Differences between the two
version information are managed using additional defines
in the top rc files.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-11-17 13:17:18 +00:00
Frediano Ziglio
4d51e5709f Convert resource information to English
They don't contain Hebrew so avoid to say so.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-11-17 13:17:12 +00:00
Frediano Ziglio
debf1fe981 Make CCD::load_api throw exception on its own
Avoid to use two different ways to handle errors.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Sameeh Jubran <sameeh@daynix.com>
2016-09-02 16:56:09 +01:00
Frediano Ziglio
b24a935335 Fails CCD initialisation if get_config_buffers detect WDDM is not present
There's no point continuing without WDDM as CCD cannot work without it.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Sameeh Jubran <sameeh@daynix.com>
2016-09-02 16:55:54 +01:00
Frediano Ziglio
67b63fe6f7 Do not print function calling vd_printf
vd_printf already print the current function

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-09-02 15:26:27 +01:00
Frediano Ziglio
75a0033f42 Use simpler classes for mutex handling
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-09-01 15:50:14 +01:00
Frediano Ziglio
ec0a2352b1 Use std::vector for agent capabilities
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-09-01 15:50:14 +01:00
Frediano Ziglio
25ef634202 Make some members constant
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-09-01 15:46:50 +01:00
Frediano Ziglio
2cb102280a Make static and constant some lookup arrays
Make clipboard_formats and image_types static and constant.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-09-01 15:46:50 +01:00
Frediano Ziglio
7555e21545 Reuse SPICE_N_ELEMENTS macro
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-09-01 15:46:50 +01:00
Frediano Ziglio
9ed7be6445 Make DisplayMode setter methods const
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-09-01 15:45:19 +01:00
Frediano Ziglio
011d60e628 Fix include syntax
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-09-01 15:45:17 +01:00
Frediano Ziglio
6bdd83d780 Remove small possible buffer overflow
wcsncpy requires number of characters, not bytes.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-09-01 15:45:11 +01:00
Sameeh Jubran
3616a7ed38 Implementing WDDM interface to support multiple monitors and arbitrary resolution
The Direct3D 9 API operates on either the Windows XP display driver
model (XPDM) or the Windows Vista display driver model (WDDM), depending
on the operating system installed.

This patch implements the WDDM interface while using the CCD API to do
so. Moreover it introduces multiple monitors support and arbitrary
resolution for Windows 10 while preserving backward compatiblity with
previous versions of Windows.

Based on a patch by Sandy Stutsman <sstutsma at redhat.com>

Signed-off-by: Dmitry Fleytman <dfleytma at redhat.com>
Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-09-01 12:32:59 +01:00
Sameeh Jubran
9c561ca8fe Update the displays only when needed
This patch updates the display configurations only when needed.
Currently vdagent updates the display configurations almost on every
"VD_AGENT_MONITORS_CONFIG" request, this approach is redundant as some
"VD_AGENT_MONITORS_CONFIG" requests don't apply any change to the
display configurations.

A good example of why this is needed, is the 'resize-guest' feature of
the spice-widget which when enabled causes the client to send periodic
"VD_AGENT_MONITORS_CONFIG" requests in order to resize the guest even
when no change is required. Prior to this patch the screen would
periodically flicker when using Virt-manager or Spicy due to this issue.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-08-30 17:15:11 +01:00
Sameeh Jubran
3856b1147a Initialize buffers before querying display config
The buffers and buffer sizes should be initialized and allocated. This
patch fixes a possible case where vdagent can get stuck, as the
function _pfnQueryDisplayConfig can return ERROR_INVALID_PARAMETER
if the buffers aren't intialized.
The call to free_config_buffers is superfluous because it is called
inside get_config_buffers.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-08-30 14:22:56 +01:00
Frediano Ziglio
f96d575659 Pass class pointer using thread parameter
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2016-08-16 15:43:21 +01:00
Frediano Ziglio
2ab513267b Don't use _singleton if we already have the right this pointer
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2016-08-16 15:43:19 +01:00
Sameeh Jubran
d81d8cdbde Encapsulating XPDM implementation
The Direct3D 9 API operates on either the Windows XP display driver
model (XPDM) or the Windows Vista display driver model (WDDM), depending
on the operating system installed.

This patch encapsulates the current XPDM interface implementation into
XPDMInterface class which inherits DisplayConfig class. This patch
makes it easier to introduce WDDM interface to Vdagent in future
patches.

Based on a patch by Sandy Stutsman <sstutsma@redhat.com>

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-08-16 11:19:02 +01:00
Sameeh Jubran
588a7134df Introducing Windows CCD API
The Connecting and Configuring Displays (CCD) Win32 APIs
provide more control over the desktop display setup. The CCD APIs
move away from using Windows Graphics Device Interface (GDI)
concepts like view name and toward Windows Display Driver Model
(WDDM) concepts like adapter, source, and target identifiers.
More info on the CCD API can be found here:
https://msdn.microsoft.com/en-us/library/windows/hardware/ff539590(v=vs.85).aspx

This patch introduces partial functionality from the CCD API
needed by vdagent. It is needed by vdagent in order to support
multiple monitors and arbitrary resolution on Windows 10.

Based on a patch by Sandy Stutsman <sstutsma@redhat.com>

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-08-16 11:19:00 +01:00
Sameeh Jubran
714801261f Update monitor state when it is detached
The monitor detached state is being set but not updated, in order to update it
we should call ChangeDisplaySettingsEx after setting the appropriate
flags along with width and height that are set to 0.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-08-16 06:37:12 +01:00
Victor Toso
3bddbd19fd vdagent: rework on event_dispatcher
As _stop_event is not mandatory, we are initializing the events array
with something that might be NULL. The problem is with the following
patch as I'm introducing a new non mandatory event and logic starts to
get a bit hard to follow.

So this patch makes explicit if we are setting or receiving a
_stop_event or not and uses an auxiliary enum and array 'actions' to
work around this non mandatory events and the return value of
MsgWaitForMultipleObjectsEx()

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-08-13 17:47:49 +02:00
Victor Toso
8ae139f363 vdagent: remove whitespaces
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-08-12 09:41:41 +01:00
Victor Toso
d6919c6c07 file-transfer: fix typo
Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-08-11 14:34:32 +01:00
Sameeh Jubran
107b351795 Fixing buffer overflow when reloading wallpaper
The function "SystemParametersInfo" expects the size of the
buffer in characters. When wchar is used instead of char - two
bytes instead of one byte per character -, then "sizeof" returns wrong
number of characters (twice as much). A suitable solution would be to use
SPICE_N_ELEMENTS.

Based on patch by Sandy Stutsman <sstutsma@redhat.com>

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
2016-08-01 14:23:28 +02:00
Victor Toso
5907b6cbb5 vdagent-win: check for locked session
>From WTSRegisterSessionNotification() we are aware of session changes
(WM_WTSSESSION_CHANGE) such as Lock/Unlock events.

We can use that to disable features such as drag-and-drop.
Tested on: Windows 7, Windows XP

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1323628
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-05-09 12:40:24 +02:00
Uri Lublin
5edf7433a4 handle_mouse_event: fix off-by-one when normalizing mouse coordinates
Mouse coordinates can be 0..(width-1) and 0..(height-1)

Normalization of mouse coordinates (for SendInput) was done
against w,h and thus right-most and down-most coordinates
could never be reached.

Fix it by normalizing against (w-1) and (h-1).

Also added protection against a case of 0 or 1 (for any of w,h)
Fixes rhbz#1032037
2016-05-05 11:47:20 +03:00
Sandy Stutsman
259d6b5bdb Check for set-monitors-position capability from client.
If the client hasn't been updated to handle multi-monitor configurations
that are not multi-head, vd_agent won't issue the MONITORS_CONFIG driver
escape.

These changes will ensure that the new MONITORS_CONFIG escape in commit:
6023630562 will not break with an older
client.

This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1248196
2015-08-06 12:01:45 +02:00
Sandy Stutsman
6023630562 Add monitors_config driver escape.
When a Windows guest uses the "Set Resolution" applet to change
resolutions and/or monitor positions, this escape sends the new monitor
configurations to the client via a new QXL driver escape.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1202419
2015-06-29 16:37:44 +02:00
Sandy Stutsman
7bac272308 Use (0,0) for Windows Primary monitors.
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1174129.

Windows considers the monitor positioned at (0,0) to be primary. VDAgent
normalizes the monitor positions so that there are no negative
coordinates. If the normalized positions are passed to the Windows APIs,
the leftmost monitor will always be set to primary. We need to keep
track of the original primary monitor and its normalized position to be
able to adjust the coordinates that are passed to Windows.
2015-06-10 13:50:19 +03:00
Frediano Ziglio
7fb2e2becc vdagent-win: Fix compile under MingW
Including directly shlobj.h in some MingW environment lead to some missing
definitions error. Including windows.h before fix the problem.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-04-30 14:01:01 +02:00
Frediano Ziglio
ae4a4f0035 Use wide characters in drap&drop code
This allows username to contain any extended characters (username is
embedded in the directory name).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-04-30 13:21:48 +02:00
Christophe Fergeau
5aa999320f Use new vdagent_{strncpy,strcat}_s helpers 2015-03-20 10:45:12 +01:00
Uri Lublin
d1c8d152f4 g_key_get_string: use size_t for pointer difference
The 64 bit Visual Studio build complains that:
  .\file_xfer.cpp(223) : warning C4244:
    '=' : conversion from '__int64' to 'unsigned int', possible loss of data
2014-12-30 17:42:17 +02:00
Uri Lublin
d752a5b6e0 Fix Visual Studio compiler warning (strncpy)
Visual Studio complains:
  vdagent\file_xfer.h(28) : warning C4996: 'strncpy': This function or variable may
  Consider using strncpy_s instead.
  To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
  See online help for details.

Replace strncpy with strcpy_s when building with Visual Studio.
Adjust parameter order and difference in meaning of length:
- length param is last in strncpy and second in strcpy_s
- many calls to strncpy are given length param n-1, as
  strncpy does not guarantee that destination ends with '\0'
- it's safer to set length param not larger than sizeof(d)
  (assuming d is an array not a pointer)

Trying to use strcpy_s for both Visual Studio and mingw
failed as strcpy_s is missing from the default msvcrt.dll
on WinXP (See OLDMSVCRT in common/vdcommon.h).
2014-12-30 17:37:26 +02:00
Uri Lublin
88b9b74d95 Fix building with Visual Studio (inttypes.h)
As a followup of commit 462295d9f8.

Building with Visual Studio, fails as there is no inttypes.h file:
  vdagent\file_xfer.cpp(21) : fatal error C1083: Cannot open
  include file: 'inttypes.h': No such file or directory

This commit prevents including inttypes.h when building with Visual Studio,
and defines PRIu64 that is defined in inttypes.h for mingw compiler.
2014-12-30 17:17:24 +02:00
Uri Lublin
dd53b1766e vdagent::handle_max_clipboard fix vd_printf format
Using unsigned long to print a size_t.
2014-12-30 17:17:24 +02:00
Uri Lublin
8a28f878b9 vdagent: as_user: reorder initialization to make mingw-gcc happy
Fixes compiler warning that starts with:

In file included from vdagent/as_user.cpp:19:0:
vdagent/as_user.h: In constructor 'AsUser::AsUser(DWORD)':
vdagent/as_user.h:35:10: warning: 'AsUser::_started' will be initialized after [-Wreorder]
     bool _started;
2014-12-30 17:17:24 +02:00
Uri Lublin
eb276f4b45 Fix compiler warning (missing backslash in FileXfer::handle_start)
Visual Studio complains:
vdagent\file_xfer.cpp(85) : warning C4129: '%' : unrecognized character escape sequence

Replace "%s\%s" with "%s\\%s"
2014-12-30 17:16:53 +02:00
Cody Chan
6c070843cb Fix g_key_get_string() failure when string contains '['
In vd_agent/file_xfer.cpp is implemented a simple g_key_get_string,
but  when dragging a file with a name containing '[' (like te[st.txt),
it will fail.
From source code,
>next_group_pos = strstr(group_pos + strlen(group_pfx), "[");
>    if (next_group_pos && key_pos > next_group_pos) return false;
we know that it tries to find the end of current group by '[' label,
if we drag a file named te[st.txt, the key_string will be like:
[vdagent-file-xfer]
name=te[st.txt
size=10
so, it will fail when meta parsing and returns the
VD_AGENT_FILE_XFER_STATUS_ERROR message.

Here's the elegant method Christophe proposed and test ok, thanks to
him again!
2014-11-13 16:52:19 +01:00
Cody Chan
21b79679c1 Fix dragging of files with CJK characters in name
I submitted a patch several months ago about this issue,
here http://lists.freedesktop.org/archives/spice-devel/2014-February/016158.html
I check it again, and find that the value of
g_key_file_to_data(keyfile,...) is always utf-8, for the value of
g_uri_list_extract_uris() is utf8 urlencode.

So the display problem is caused by vd_agent, but how it displays
depends on the language of system, the following two screenshots show
the difference:

http://int64ago-tmp.qiniudn.com/guest-Chinese.png
http://int64ago-tmp.qiniudn.com/guest-English.png
2014-11-13 16:52:18 +01:00
Marc-André Lureau
6d1c038a8c Don't refresh displays config when updating
wnd_proc() is called during ChangeDisplaySettings(), when handling
monitors config. However, calling get_displays() will overwrite the
desired config.

So, while updating from 1 to 4 enabled monitors, when the 2nd monitor
config is enabled, the current config is read, and overwrite the rest of
the config, so first time only 2nd monitor is enabled, second time, 3rd
monitor etc.

https://bugzilla.redhat.com/show_bug.cgi?id=1111144
2014-06-19 19:15:39 +02:00
Uri Lublin
4171d11bb6 vdagent: clipboard: Add VD_AGENT_CAP_MAX_CLIPBOARD support
Do not send clipboard data bigger than last received
VDAgentMaxClipboard.

If a larger amount of data needs to be transferred between client and guest,
a different mechanism should be used, not clipboard.

The spice-protocol git-submodule is updated to include VD_AGENT_MAX_CLIPBOARD
and related definitions.
2014-03-09 18:55:42 +02:00