Commit Graph

114 Commits

Author SHA1 Message Date
Frediano Ziglio
5017510709 Add support for additional buttons (side and extra)
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2022-11-08 08:00:45 +00:00
Frediano Ziglio
fbcbd9a10c Remove warning compiling
Remove an alignment warning

vdagent/vdagent.cpp: In member function 'bool VDAgent::handle_announce_capabilities(const VDAgentAnnounceCapabilities*, uint32_t)':
vdagent/vdagent.cpp:1048:48: warning: taking address of packed member of 'VDAgentAnnounceCapabilities' may result in an unaligned pointer value [-Waddress-of-packed-member]
 1048 |     _client_caps.assign(announce_capabilities->caps, announce_capabilities->caps + caps_size);
      |                         ~~~~~~~~~~~~~~~~~~~~~~~^~~~

Not a real issue, just annoying.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2022-06-16 10:23:24 +01:00
Jakub Janků
630da73bf8 clipboard: enable copying files from client using webdav
When the user wants to copy files, new spice-gtk can share those
files using the existing phodav server. In that case, it advertises
the VD_AGENT_CLIPBOARD_FILE_LIST type in the clipboard grab message.

Upon request of the clipboard data in the mentioned type, spice-gtk
provides a list of absolute paths in the phodav server - these are
the files that are supposed to be copied/moved.

The role of the vdagent is to adjust this data given the drive
letter of the mapped webdav share.

Files can be both copied and moved, although move was tested
only with Windows' File Explorer.

Copying files from the vdagnet side to the client is not
supported yet.

Signed-off-by: Jakub Janků <jjanku@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-07-31 12:48:28 +01:00
Frediano Ziglio
ab6a4a0e18 Move set_display_depth from VDAgent to DesktopLayout
The function only change DesktopLayout.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@redhat.com>
2020-07-03 16:51:02 +01:00
Frediano Ziglio
fa2e3371c8 vdagent: Reset properly state of pending large messages upon disconnection
If the client closes the connection while having pending large messages
(split into multiple chunks) the state is not correctly reset causing
next client messages to be not correctly handled.

This can occur for instance if the client is closed (or killed) while
transferring a large file.

This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1548419.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-05-15 15:22:52 +01:00
Frediano Ziglio
0fe97cc05a Use final capabilities to check client messages
The client is sending messages that are compatible with agent
capabilities but also encoded with capabilities it knows of so to
check them we need to consider final capabilities, not client ones.

This fixes a regression introduced with
"vdagent: Reuse agent_check_message" where some messages were wrongly
interpreted as wrong (particularly some clipboard messages).

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Jakub Janků <jjanku@redhat.com>
2020-05-15 11:50:08 +01:00
Frediano Ziglio
9de1492446 vdagent: Reuse agent_check_message
That function does also more checks on the message.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jakub Janků <jjanku@redhat.com>
2020-04-28 16:50:13 +01:00
Frediano Ziglio
ab3353b579 vdagent: Return better error if locked
Use specific VD_AGENT_FILE_XFER_STATUS_SESSION_LOCKED error.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-24 10:33:34 +01:00
Frediano Ziglio
a914784295 vdagent: Allow to return detailed message for file transfer
Reuse AgentFileXferStatusMessageFull and agent_prepare_filexfer_status

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-24 10:33:34 +01:00
Frediano Ziglio
5988f86a75 Revert 3 last patches
Revert "try to remove other bugs", commit
57266085b9.
Revert "try to fix previous", commit
8e40377068.
Revert "attempt to fix more warnings!", commit
66b6933a38.

I put by mistake on the MR due to some automatic scripts.
Their state are pretty experimental.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-30 15:11:22 +01:00
Frediano Ziglio
8e40377068 try to fix previous 2020-03-23 13:57:06 +00:00
Frediano Ziglio
66b6933a38 attempt to fix more warnings! 2020-03-23 13:38:40 +00:00
Frediano Ziglio
0ad43eed50 Constification, does not make sense to change the messages processing them
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-01-10 12:56:25 +00:00
Frediano Ziglio
9207d821d2 file_xfer: Open Download directory after a file transfer is finished
Have the same behaviour of Linux machines.
The directory is not opened again and again, only is not already
opened.
This is done checking the directory opened in explorer.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-11-18 10:30:14 +00:00
Jonathon Jongsma
8bbb89e92b Don't exit when receiving unknown messages
In 8251fa25, a check on the minimum size of a message was introduced.
For unsupported messages, the vdagent simply exited. This makes it
inconsistent with previous behavior and inconsistent with the behavior
of the linux vdagent.  Instead, just print a warning indicating that an
unsupported message was received and ignore it.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-05 13:50:08 +00:00
Frediano Ziglio
348f7ed0cd Use GetModuleHandle to get some functions from user32 library
The library is surely already loaded as providing clipboard and
other utilities we need.
user32 is one of the main win32 libraries.
Avoid using LoadLibrary that increment the reference so we don't
need to call FreeLibrary to cleanly decrement the reference.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-07-19 12:20:49 +01:00
Frediano Ziglio
9264c7f367 vdagent: Add a comment around WinSta0_DesktopSwitch event usage
Multiple times while I was reading this code was not clear why the
synchronization of this event was not done in the main event loop.
Also document why we want to use it not relying just on
WTSRegisterSessionNotification and WM_WTSSESSION_CHANGE.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-07-19 12:07:27 +01:00
Frediano Ziglio
7038aa83b3 vdagent: Stop correctly helper thread
The thread launched to detect desktop switches events is not stopped
correctly causing potentially dandling pointers.
Queue a APC to make the loop exit and wait for thread termination
from the main thread.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-07-18 11:47:20 +01:00
Frediano Ziglio
2ae3bd5b9c Use destructor instead of cleanup function
More C++ style.
Also avoids missing cleanup calls.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-07-18 11:07:01 +01:00
Frediano Ziglio
0ac9d687e9 Introduce an helper to close VirtIo device
Do not assume we allocated the handle doing the cleanup.
This utility will be reused in next patch.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe de Dinechin <dinechin@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-07-18 11:05:50 +01:00
Frediano Ziglio
6d1d4241ac Use proper invalid value for _vio_serial
For some reason kernel handles in Windows have 2 invalid values
depending on the type. Files/devices use INVALID_HANDLE_VALUE (-1),
while others use NULL (0). As _vio_serial is a file, created
with CreateFile, use INVALID_HANDLE_VALUE for consistency.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-07-18 11:05:05 +01:00
Frediano Ziglio
55290d1766 Avoids to call supported_system_version()
The only reason we call this function is to check if the
system should support some APIs.
Instead just check directly if these APIs are supported
calling GetProcAddress directly.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-07-05 18:35:31 +01:00
Frediano Ziglio
e9421d09b8 Avoid declaring _system_version member
The check can be done a single time, no reason to cache
supported_system_version() value.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-07-05 16:38:04 +01:00
Frediano Ziglio
c0a6e42e80 Avoid declaring event_thread_id
As the value is never used we can pass NULL in CreateThread.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-07-05 14:50:36 +01:00
Frediano Ziglio
6a0683707f Allocate _control_event and _stop_event just once
Handle _control_event and _stop_event destruction in destructor.
Allows to call VDAgent::run multiple time if needed.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-07-05 14:25:42 +01:00
Frediano Ziglio
0984079e08 Use std::unique_ptr for _desktop_layout
Make automatic the release of this pointer.
Also avoids having a leak if VDAgent::run is called twice.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-07-05 13:26:05 +01:00
Frediano Ziglio
18cbe9f306 Replace an assert with proper handling code
Make sure the condition is handled properly.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-07-04 05:33:22 +01:00
Frediano Ziglio
3e8cab6da1 Minor overflow checks improvements
Although source of these data should be safe, improve data checks
to avoid some overflows and make the code more robust.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-07-04 05:33:22 +01:00
Frediano Ziglio
873464cecc Reduce indentation returning earlier
Also add some comments.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-07-04 05:33:22 +01:00
Frediano Ziglio
bc3384f359 Use proper type for _clipboard_owner
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe de Dinechin <dinechin@redhat.com>
2018-07-03 14:30:12 +01:00
Frediano Ziglio
8251fa25ac Minimal message size check
Avoid some possible integer overflows.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2018-06-29 19:51:55 +01:00
Frediano Ziglio
ae94c50ee9 Use enumeration types
No reasons to allow any possible number.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-06-29 19:34:57 +01:00
Frediano Ziglio
531dd85f60 Reuse spice-protocol macros instead of defining new ones for alignment
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-06-28 02:17:32 +01:00
free.user.name
b291e4ca14 vdagent: Fix loss of mouse movement events
send_input() may not be immediately called from handle_mouse_event() on
movement. INPUT structure is generated and stored and a timer may be set
instead. If subsequent call to handle_mouse_event() occurs before timer
expires, prepared INPUT structure gets overwritten and MOUSEEVENTF_MOVE
bit is lost. Windows doesn't see updated mouse position as the result.

Make handle_mouse_event() merely store the new mouse state, and move
INPUT structure generation to send_input(). Shuffle new mouse state to
previous only after mouse events are submitted to SendInput() Windows
API function.

This patch was sent to the mailing list by an anonymous contributor
with minimal style changes.

You can easily test increasing VD_INPUT_INTERVAL_MS (like 1000).
For instance you can try in a word processor to move the cursor
clicking the mouse on different positions.

Acked-by: Victor Toso <victortoso@redhat.com>
2018-05-31 13:02:21 +01:00
Frediano Ziglio
2aa6f16af4 vdagent: Removed unused declaration
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-05-25 11:59:59 +01:00
Frediano Ziglio
0fd4882477 Move image handling to a separate file
This will make easier to change code that handle images.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-07-26 08:52:15 +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
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
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
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
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
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