Commit Graph

2090 Commits

Author SHA1 Message Date
Victor Toso
fcdc04dc83 main: to let SpiceFileTransferTask handle errors
* on VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA, if the file-transfer is
  on pending state, spice_file_transfer_task_read_async() will call the
  callback with error set.

* on VD_AGENT_FILE_XFER_STATUS_SUCCESS, if the file-transfer is on
  pending state, spice_file_transfer_task_completed() will set the
  error for this task.

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-07-07 16:19:23 +02:00
Victor Toso
202ff31fe4 file-xfer: introduce functions to read file async
Introduced functions (private):
* void   spice_file_transfer_task_read_async()
* gssize spice_file_transfer_task_read_finish()

For a better abstraction of how to read from SpiceFileTransferTask and
handle its data, following the design of other objects like GFile and
GInputStream.

Due to the logic changes involved, some functions were created or
renamed to better address or match its place and purpose:

* spice_file_transfer_task_read_stream_cb
  Callback for the actual read from GInpustStream; This is handling
  the SpiceFileTransferTask bits only;

* file_xfer_read_cb -> file_xfer_read_async_cb
  Renamed to match _read_async() function; This is handling the data
  from reading the file by flushing it to the agent.

As the _read_async() uses GTask, the error handling is done on the
channel-main's callback, after _read_finish() is called.

This change is related to split SpiceFileTransferTask from
channel-main.

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-07-07 16:19:23 +02:00
Victor Toso
4647ac9a2a file-xfer: introduce functions to init task async
Introduced functions (private):
* void       spice_file_transfer_task_init_task_async()
* GFileInfo *spice_file_transfer_task_init_task_finish()

The init process of SpiceFileTransferTask does initialize its
GFileInputStream (for reading the file) and also its GFileInfo
(necessary to protocol in order to start the file-transfer with agent)

Due the logic changed involved, some functions were renamed to better
match its place and purpose:

* file_xfer_info_async_cb -> file_xfer_init_task_async_cb
  It is channel-main's callback for each _init_task_async()

* file_xfer_read_async_cb -> spice_file_transfer_task_read_file_cb
* file_xfer_info_async_cb -> spice_file_transfer_task_query_info_cb
  Both should be private to SpiceFileTransferTask now.

As the _init_task_async() uses GTask, some error handling was moved to
channel-main's after _init_task_finish() is called.

This change is related to split SpiceFileTransferTask from
channel-main.

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-07-07 16:19:23 +02:00
Victor Toso
f6b3b69709 file-xfer: introduce _create_tasks()
We can split from file_xfer_send_start_msg_async() the logic in
creating the SpiceFileTransferTasks; The rest of the function can be
handled at spice_main_file_copy_async().

The new function, spice_file_transfer_task_create_tasks() returns a
GHashTable to optimize the access to a SpiceFileTransferTask from its
task-id, which is what we receive from the agent.

This change is related to split SpiceFileTransferTask from
channel-main.

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-07-07 16:19:23 +02:00
Victor Toso
cc73487e9d file-xfer: get functions for SpiceFileTransferTask
In order for channel-main to interact with each SpiceFileTransferTask
for the file-transfer operation, the following functions are
introduced:
* spice_file_transfer_task_get_id
* spice_file_transfer_task_get_channel
* spice_file_transfer_task_get_cancellable

Note that "id" property is public and could be acquired by
g_object_get but having the helper function is more practical.

This change is related to split SpiceFileTransferTask from
channel-main.

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-07-07 16:19:23 +02:00
Victor Toso
2fbdb68afa file-xfer: task-id to start with 1
As this is unsigned, we can let 0 be in case of error

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-07-07 16:19:23 +02:00
Christophe Fergeau
c0ccc8144e usb-device-manager: Avoid USB event thread leak
This is a follow-up of the previous commit ('usb-channel: Really stop
listening for USB events on disconnection').

Since the USB event thread has to be stopped when we destroy the
associated SpiceUsbDeviceManager, spice_usb_device_manager_dispose()
should force event_thread_run to FALSE even if
spice_usb_device_manager_stop_event_listening() was not enough. When
this happens, this means that there is a bug in the internal users of
spice_usb_device_manager_start_event_listening(), but with this change,
we'll at least warn about it, and avoid a thread leak/potential future
crash.
2016-06-30 18:16:10 +02:00
Christophe Fergeau
4a777ec0a6 usb-channel: Really stop listening for USB events on disconnection
When using USB redirection, it's fairly easy to leak the thread handling
USB events, which will eventually cause problems in long lived apps.
In particular, in virt-manager, one can:
- start a VM
- connect to it with SPICE
- open the USB redirection window
- redirect a device
- close the SPICE window
-> the SpiceUsbDeviceManager instance will be destroyed (including the
USB context it owns), but the associated event thread will keep running.
Since it's running a loop blocking on libusb_handle_events(priv->context),
the loop will eventually try to use the USB context we just destroyed
causing a crash.

We can get in this situation when redirecting a USB device because we
will call spice_usb_device_manager_start_event_listening() in
spice_usbredir_channel_open_device(). The matching
spice_usb_device_manager_stop_event_listening() call is supposed to
happen in spice_usbredir_channel_disconnect_device(), however by the
time it's called in the scenario described above, the session associated
with the channel will already have been set to NULL in
spice_session_channel_destroy().

The session is only needed in order to get the SpiceUsbDeviceManager
instance we need to call spice_usb_device_manager_stop_event_listening()
on. This patch stores it in SpiceChannelUsbredir instead, this way we
don't need SpiceChannel::session to be non-NULL during device
disconnection.

This should fix the issues described in
https://bugzilla.redhat.com/show_bug.cgi?id=1217202
(virt-manager) and most
likely https://bugzilla.redhat.com/show_bug.cgi?id=1337007 (gnome-boxes)
as well.
2016-06-30 15:32:46 +02:00
Christophe Fergeau
76ad9f2682 usb: Update outdated GSimpleAsyncResult comment
It's still true after the switch to GTask.
2016-06-30 15:27:15 +02:00
Christophe Fergeau
eaededfa67 usbredir: Use atomic for UsbDeviceManager::event_thread_run
This variable is accessed from 2 different threads (main thread and USB
event thread), so some care must be taken to read/write it.
2016-06-30 15:27:15 +02:00
Marc-André Lureau
8c3a78e4bd usbredir: mark some functions as internal
For the sake of making clear those are not exported.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-06-30 10:39:35 +02:00
Christophe Fergeau
183c84d07c usbredir: Fix GTask leak
spice_usbredir_channel_disconnect_device_async() creates a GTask and
then calls g_task_run_in_thread(). This method will take the reference
it needs on the GTask, it does not take ownership of the passed-in
GTask. This means we need to unref the GTask we created after calling
g_task_run_in_thread(), otherwise we are going to leak the GTask, as
well as the channel it's associated with.
Since it's an USB redir channel, this also causes some USB device
manager/USB event thread leaks.
2016-06-30 10:09:04 +02:00
Marc-André Lureau
15432988ec Update NEWS for 0.32 release
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-06-21 16:11:55 +02:00
Pavel Grunt
ea37f06eaa session: Keep brackets around ipv6 hostname
According to rfc2732:
"To use a literal IPv6 address in a URL, the literal address should be
enclosed in "[" and "]" characters."

Resolves: rhbz#1331777

Acked-by: Marc-André Lureau <mlureau@redhat.com>
2016-06-21 15:25:35 +02:00
Pavel Grunt
20a423f78d session: Removed write-only variable
Acked-by: Marc-André Lureau <mlureau@redhat.com>
2016-06-21 15:24:40 +02:00
Marc-André Lureau
339ec65be4 mailmap: fix my name
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-06-21 14:37:00 +02:00
Victor Toso
7b947d4206 main: channel-main to increase file-transfer reference
This is a minor fix in the logic as in both situations (with or
without the patch) the reference count for the SpiceFileTransferTask
object is the same.

The change is interesting as SpiceFileTransferTask is created but on
g_file_read_async() it increases its reference count while
c->file_xfer_tasks keeps the original one.

It should be the other way around.
Acked-by: Marc-André Lureau <marcandre.lureau@gmail.com>
2016-06-21 14:08:28 +02:00
Victor Toso
f7a1914796 main: assign variable after check for null
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-06-21 14:07:46 +02:00
Christophe Fergeau
ed876b4cc9 build: Fix _DEPENDENCIES use
We want to trigger rebuild of libspice-client-gtk-3.0.la or
libspice-client-glib-2.0.la whenever the corresponding symbol file
changes.
However _DEPENDENCIES is not the right way of handling that as it will
disable automatic automake dependency generation.
This was not causing issues mainly because _DEPENDENCIES was mispelt as
_DEPEDENCIES.

Quoting automake manual:
https://www.gnu.org/software/automake/manual/automake.html#index-EXTRA_005fmaude_005fDEPENDENCIES-1
« The EXTRA_*_DEPENDENCIES variable may be useful for cases where you
merely want to augment the automake-generated _DEPENDENCIES variable
rather than replacing it. »

So this commit switches to use EXTRA_*_DEPENDENCIES rather than
*_DEPENDENCIES.
2016-06-20 18:20:21 +02:00
Marc-André Lureau
14c02c2873 build-sys: fix win32 build
Commit 0fafbe3 broke the build on win32, because it accesses
d->egl.enabled. Add a helper function and fix the build.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reported-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-06-20 17:13:13 +01:00
Marc-André Lureau
1cefbe59e7 vncdisplaykeymap: fix -Werror=tautological-compare
vncdisplaykeymap.c: In function 'vnc_display_keymap_gdk2xtkbd_table':
vncdisplaykeymap.c:223:14: error: self-comparison always evaluates to true [-Werror=tautological-compare]
  if (GDK_IS_WIN32_WINDOW(window)) {

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-06-20 17:12:35 +01:00
Marc-André Lureau
0fafbe3d9e widget: fix keyboard ungrab after click
Since the switch to a container widget (gtkstack then gtkeventbox), the
grab may be lost when clicking on the display. Since events are treated
at the top level container, set widget "above-child" to trap all of them
to solve this.

Fixes:
https://bugs.freedesktop.org/show_bug.cgi?id=96595

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reported-by: Frediano Ziglio <fziglio@redhat.com>
Tested-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Fabiano Fidêncio <fidencio@redhat.com>
2016-06-20 17:35:26 +02:00
Marc-André Lureau
a3d686fb16 widget: use scanout offset when using virgl
Ignoring the display area offset doesn't work nicely with virgl. Imho,
this condition is wrong even in QXL case.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-06-20 15:18:10 +02:00
Alexandru Visarion
088b15742e channel-main: Fix spice_main_file_copy_async annotation
Without (array zero-terminated=1), one null terminated array
parameter is translated into a single element, so its binding
isn't usable.

Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-06-17 12:59:31 +02:00
Frediano Ziglio
7d881d2193 widget: Disable IME context on display widget
This prevent Windows to handle IME on the widget which cause the
application to not receive keyboard events.

To test this issue set keyboard layout to Japanese and Microsoft
IME (the default one). Set the input method to full katakana, assure
your remote-viewer is using this method and start pressing
alphabetical keys. On the guest (open a terminal, an editor or
a word processor to make easier) you won't see any character.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-16 15:52:07 +01:00
Christophe Fergeau
3e3b37b672 main: Don't delay update_display_timer(0) for up to 1 second
When using remote-viewer --full-screen with a VM/client with multiple
monitors, a race can be observed during auto-configuration. First, the
client monitors config is sent to the guest:
(remote-viewer:19480): GSpice-DEBUG: channel-main.c:1166 main-1:0: sending new monitors config to guest
(remote-viewer:19480): GSpice-DEBUG: channel-main.c:1183 main-1:0: monitor #0: 1920x1080+0+0 @ 32 bpp
(remote-viewer:19480): GSpice-DEBUG: channel-main.c:1183 main-1:0: monitor #1: 1920x1080+1920+0 @ 32 bpp

Then we receive messages from the agent which trigger a call to
update_display_timer(0)

This should cause the current monitors state to be sent to the server
very soon after this call. However, in the racy case, this is delayed
for nearly a second, and timer_set_display() ends up being called at the
wrong time, when information about the first display channel have been
received from the server, but not the second one.

When this happens, we inform the server that only one monitor is active,
then the server sends a MonitorsConfig message with 2 monitors (first
request we sent), and then with just 1 monitor (second request we sent).

This causes remote-viewer to show one fullscreen black window indicating
"Connected to server" on one monitor and a working fullscreen window on
the second monitor.

update_display_timer(0) schedules a timeout to be run with
g_timeout_add_seconds(0). However, g_timeout_add_seconds() schedules
timers with a granularity of a second, so the timeout we scheduled with
g_timeout_add_seconds() may fire up to 1 second later than when we
called it, while we really wanted it to fire as soon as possible.
Special-casing update_display_timer(0) and using g_timeout_add() in that
case avoid this issue. In theory, the race could probably still happen
with a very very bad timing, but in practice I don't think it will be
possible to trigger it after this change.

https://bugzilla.redhat.com/show_bug.cgi?id=1323092
2016-06-15 15:30:27 +02:00
Alexander Bokovoy
fb8e51667b sasl: fix SASL GSSAPI by allowing NULL username
SASL GSSAPI module will try to negotiate authentication based on the
credentials in the default credentials cache. It does not matter if
SPICE knows username or not as SASL negotiation will pass through the
discovered name from the GSSAPI module.

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
Acked-by: Fabiano Fidêncio <fidencio@redhat.com>
2016-06-15 15:24:21 +02:00
Frediano Ziglio
9b83e9a7c8 Remove some warnings compiling for Windows
GetLastError returns a DWORD which is a "unsigned long" on Windows
so use "%lu" formatting instead of "%u".

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Marc-André Lureau <mlureau@redhat.com>
2016-06-13 12:51:51 +01:00
Pavel Grunt
3c8fb7e24d channel-display: Remove deprecated init functions
They are called at the construct time since spice-common commit:
5b6be16b37370bb774aa3c2a7d5c41791fdc3a1e
2016-06-13 13:07:47 +02:00
Pavel Grunt
8cf25bea7b tests-uri: Define g_assert_nonnull
It is available since Glib 2.40
2016-06-13 13:07:47 +02:00
Pavel Grunt
2253df177e Require gtk+ 3.12
Allow to use gtk_stack_get_child_by_name
2016-06-13 13:07:47 +02:00
Frediano Ziglio
99f357d6a5 widget: Do not mix function linkage
This prevents a possible crash on windows 32 bit.
The linkage of UnhookWindowsHookEx is WINAPI which is __stdcall while
callback for g_clear_pointer is C. This could cause stack pointer
corruption depending on compiler flags.
On __stdcall linkage function change the stack pointer while returning
from a function removing the parameters. On C linkage function leave
the stack pointer unchanged. So if the compiler call a __stdcall
function as a C function it expect the stack pointer to be unchanged
causing the pointer to be inconsistent by an offset.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-06-13 10:19:32 +01:00
Frediano Ziglio
3e08aef2d3 widget: Do not ignore unsupported keys from keyboard
If Windows layout does not support a given key the resulting virtual code
is set to 0xFF. To avoid losing this raw key (causing the key not been
sent to remote machine) detect this condition and handle the key.
The check for raw scancode is there to understand if we can handle
correctly the key in following code.
This problem can happen for instance using a 106 key Japanese keyboard
while the layout is set in English; in this case keys like CONVERT not
forwarded correctly.

Some note on how to reproduce and test this problem.

Physical way:
1- get a 106 key Japanese keyboard for your Windows client machine;
2- setup your client to English keyboard layout;
3- connect to a Linux machine (no matter the distro or version or
   keyboard configuration);
4- open "xinput test-xi2 <device>" command on Linux (device is
   the "AT" device in this case);
5- press CONVERT or other keys not present on an English keyboard.

Virtual way (Windows machine on a VM):
- set machine remote to VNC;
- assure Qmeu has lock-key-sync=off option to vnc;
- connect to Windows machine with a VNC client (I suggest TigerVNC
  as remote-viewer do some keyboard insertion);
- do steps 2, 3, 4 above
- press the CONVERT key. If you don't have you can simulate, either
  - change VNC client code to insert scancode 0x70 instead of another
    key and press this key;
  - disconnect main VNC client and use some tool to inject keys
    (I use a modifier version of vncdotool).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-09 11:28:53 +01:00
Francois Gouget
b2e6f64da9 streaming: Use the frame dimensions reported by the video decoder
The dimensions sent by the remote end are redundant and should not be
trusted.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-06-06 14:02:16 +02:00
Pavel Grunt
3666ec4d5c widget: Avoid using GDK_GRAB_FAILED defined in Gtk 3.16.
The returned value from do_pointer_grab() is treated as a boolean - grab
was successful or not. Change the function to return a boolean value.

Reported-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2016-06-06 14:01:55 +02:00
Pavel Grunt
0fb13d68dc mingw: Fix -Werror format & missing-prototypes
-Wmissing prototypes were enabled in d5e3a4a5c3
format warnings were added in da8ecf1f95
2016-06-06 13:58:52 +02:00
Pavel Grunt
08ab6d47c6 spicy: Do not show underscore in label
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2016-06-03 11:41:23 +02:00
Pavel Grunt
b542dfa2d5 spice-uri: Add ipv6 support
Just basic support -  http://user:password@[host]:port

Resolves: rhbz#1335239
2016-06-02 10:26:10 +02:00
Pavel Grunt
8dcb4129ac spice-uri: Validate uri scheme
Related: rhbz#1335239

Acked-by: Victor Toso <victortoso@redhat.com>
2016-06-02 10:26:10 +02:00
Pavel Grunt
eacbe261d4 spice-uri: Check if port is in allowed range
Use g_ascii_strtoll because it helps to detect overflow.

Related: rhbz#1335239

Acked-by: Victor Toso <victortoso@redhat.com>
2016-06-02 10:26:10 +02:00
Pavel Grunt
85051b06c1 spice-uri: Do not allow empty port string
Related: rhbz#1335239

Acked-by: Victor Toso <victortoso@redhat.com>
2016-06-02 10:26:10 +02:00
Pavel Grunt
024eccefba spice-uri: Reset SpiceURI before parsing
Avoid using old values after parsing a new uri.

Related: rhbz#1335239
2016-06-02 10:26:10 +02:00
Pavel Grunt
dab190d8d2 tests: Add test for SpiceURI
Related: rhbz#1335239
2016-06-02 10:26:10 +02:00
Francois Gouget
3b306b1430 streaming: Tweak the GStreamer decoder to avoid a compiler warning
We check that there is a matching frame in the queue before popping the
old ones. So we know the inner loop will find a match and thus that
frame will not be NULL. But figuring that out is too hard for the
compiler.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
Reported-by: Marc-André Lureau <marcandre.lureau@gmail.com>
2016-06-01 13:36:28 +02:00
Marc-André Lureau
da8ecf1f95 build-sys: update manywarnings.m4
Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-06-01 11:05:55 +02:00
Marc-André Lureau
b32398ef4d build-sys: -Wshift-overflow=2
manywarnings.m4 update will bring new flags that fail with some
glib/gst headers.

Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-06-01 11:05:48 +02:00
Marc-André Lureau
48bbcbbc49 Fix many -Werror=format warnings
Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-06-01 11:05:41 +02:00
Marc-André Lureau
67011b2c8b build-sys: remove -Wmissing-declarations
The warning doesn't show up anymore.

Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-06-01 11:05:32 +02:00
Victor Toso
7d7382ea45 channel: avoid crash on spice_channel_wakeup due NULL channel
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-06-01 09:32:39 +02:00
Victor Toso
756f1fe8aa tests: fix build with smartcard enabled
In file included from
../spice-common/common/client_marshallers.h:29:0,
from ../src/spice-channel-priv.h:35,
from ../src/spice-file-transfer-task-priv.h:28,
from file-transfer.c:3:
../spice-common/common/messages.h:45:23: fatal error: libcacard.h: No such file or directory
compilation terminated.

Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-06-01 09:32:27 +02:00