Commit Graph

3713 Commits

Author SHA1 Message Date
Frediano Ziglio
176970f3f1 red-channel-client: Remove GObject type
Make all RedChannelClient hierarchy a C++ class.
This allows to use virtual methods.
Added a normal contructor instead or properties and g_object_new.

As we remove GObject conversion macros I added a macro XXX_CAST
to create a function to replace the old macro.
They will be removed when more type safety is introduced.

There's a new SPICE_CXX_GLIB_ALLOCATOR macro in red-common.h.
This macro, added to a class define the class allocator allowing
to use, in this case, GLib for allocation. This to avoid C++ library
dependency and to initialize all structure to 0 (not all fields
are manually initialized, will be improved with more encapsulation).

Currently the methods are mainly public, access will be modified
when more encapsulation (all functions in method) are done.

Some classes are now defined in the header, C++ uses access to
limit accessibility but for efficiency and type safety/inline and
other features require types to be defined in the headers.

Some fields were moved from XxxPrivate structure to class, C++
has accessibility.

Many destructors are defined as protected to forbid the use of
stack, this as these objects uses internal reference counting
to have normal pointers. Maybe in the future pointers like
std::shared_ptr could be used instead.

Reference counting is now implemented very easily using atomic
operations.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
38cd152952 automake: Link with C++ linker
If automake sees no C++ files in the source it assumes have to
use C linker settings not linking C++ library.
This was not a problem as code did not use C++ libraries but next
patch will use pure virtual function call.
It could be provided but as later we will use RTTI use C++ library.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
6e14b6bc99 Reimplement video-codes update with no GObject signals
This is in preparation to remove GObjects, as signals require them.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
69fbef6fff Add RedChannel::(un)ref for reference counting and use them
This will reduce code to avoid gobject and make code less
type unsafe.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
3a05720eaa Introduce some utilities for C++
red::add_ref will be used to increment a reference counter
and return the object pointer.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
77af39d6b5 Update header style
Avoid typedef useless in C++.
Remove useless forward declarations.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
8671f659f4 Constify some methods
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
552c26b0a8 Move all red_channel_* functions in header as methods
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
874e745088 Move all red_channel_client_* functions in header as methods
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
2b078c44d7 Remove COMMON_GRAPHICS_CHANNEL where possible
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
08fab74cd7 Avoid useless downcast to RedChannelClient or RedChannel
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
3720e5a686 Remove RED_CHANNEL where possible
Used Coccinelle:

@@
expression E;
@@

-RED_CHANNEL(E)
+E

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
e204677a43 Remove RED_CHANNEL_CLIENT where possible
Used Coccinelle:

@@
expression E;
@@

-RED_CHANNEL_CLIENT(E)
+E

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
e6e6ded681 Use C++ IS-A relationship for RedChannelClient and RedChannel
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
e788e6e476 Remove conversion warnings
Use casts to avoid all that warning.
They should go away once you use more type safe types.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
17a7251e56 Remove warnings about combining GParamFlags types
C++ thread enum a bit more safely than C not allowing to combine
them. Avoid warning combining them and passing to functions
expecting enums.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
d8b1519c35 Remove -Wliteral-suffix warnings
Avoids warnings like

main-channel-client.cpp:538:27: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
    "net test: latency %f ms, bitrate %"G_GUINT64_FORMAT" bps (%f Mbps)%s",
    ^

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
2561f1db94 Avoid conversion warnings calling Windows sockets
Some Windows socket functions accepts char* instead of classic void*
causing some warning. Force the cast.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
e54224730e Change string check
In C++ GLib add function declaration (function parameters).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
6db395dc74 Make sure empty structure are ABI compatible
Empty structure are not really portable however adding
an zero size array seems to be the way to have a zero
size structure portably.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
2f7474427b Do not leave not initialized fields in the middle
Some old GNU compilers does not allow this (like CentOS 7 one)

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
e0b395fb68 Declare exported functions as C
Allows to be used by both C and C++ code.
So to leave part of the code in C and part move to C++.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
238f53d702 Declare public exported functions as C
Allows to link externally from a C program.
This will allow C++ code to respect C ABI.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
505b90e179 Avoid double definitions
In C++ that code would define variable twice giving error.
Define only one.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
48adb67c13 Fix order of initializers
C++ complaints if they are not in the order of
declaration.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
81c04623ea Avoid to use reserved C++ keywords
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
7b36374170 Adjust some warnings
Remove -Werror and add -fpermissive, this will allow to compile C code with
a GNU C++ compiler.

Ignore warnings as our code use some feature like empty arrays.

Remove warnings not available in C++.

Bump GLIB_VERSION_MAX_ALLOWED to reduce the warning, looks like the
GLib headers for C++ are not able to handle them correctly.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
c4b4b967fb Allows C++ to be used in sources
Enable C++ compiler

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
bea4ad66b9 char-device: Remove pool handling
Memory pool handling does not give much but make code more complex.
Current implementation tends to only increasing buffer sizes
leading to potential cases where most of the allocated memory is
not used.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:08 +01:00
Frediano Ziglio
1fbb58ac52 Fix compatibility with SOL_TCP and Darwin
Under Darwin SOL_TCP is not defined. Use IPPROTO_TCP instead.
Other part of SPICE server uses this constant instead already.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-20 15:17:59 +01:00
Frediano Ziglio
717ed19a8b Constify display_channel_update_monitors_config config parameter
No reason to change the structure.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2020-04-20 14:47:34 +01:00
Frediano Ziglio
01bbdbd281 red-qxl: Fix spice_qxl_update_area function indentation
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2020-04-17 18:59:55 +01:00
Frediano Ziglio
974692bda1 spice-qxl: Fix typo in callback name and remove obsolete parameter
attache_worker was always spelled wrongly.
Use anonymous union (standard feature already used in different
code in SPICE) to have an aliased attached_worker function.
Also removed a parameter from this new callback and deprecate
the old.
Due to C ABI removing a parameter is not an issue,
red-qxl.c:red_qxl_attach_worker will continue to pass the parameter,
new code will ignore, old code will receive it.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-16 11:08:14 +01:00
Frediano Ziglio
6826487237 red-qxl: Avoid function that just call another static function
Inline the function directly, avoid useless function and developers
having to go up and down the code just to understand what these
function do.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-16 11:08:14 +01:00
Frediano Ziglio
6aa1a17c69 spice-qxl: Remove QXLWorker definition
It was made obsolete more than 6 years ago by

  commit fe0941fb02
  Author: Marc-André Lureau <marcandre.lureau@gmail.com>
  Date:   Thu Oct 3 22:52:38 2013 +0200

      server: mark deprecated symbols

For compatibility with spice_replay_next_cmd pass a QXLInstance
pointer. For more information see comment on
red-qxl.c:red_qxl_attach_worker.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-16 11:08:13 +01:00
Frediano Ziglio
2f130edfdd test-display-base: Remove only written "qxl_worker" from Test
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-13 15:55:11 +01:00
James Le Cuirot
f00224a094 build: Use Meson's pkgconfig module to generate the .pc file
The existing .pc file had the wrong dependencies for Windows and was
missing the optional private dependencies for static linking.

Signed-off-by: James Le Cuirot <chewi@gentoo.org>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-08 18:57:52 +01:00
Frediano Ziglio
94a4578c87 Set SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION in RedChannel
Is set in any case, but do it once instead of every time
one client connects.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-08 07:42:47 +01:00
Frediano Ziglio
595132dca8 ci: Fix for test-set-ticket leak detection
This suppression was present in former glib.supp version however
the suppression in glib.supp was updated to only catch "reachable"
leaks.
In early stages and few objects the leak could be detected as
"possible".

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-03 14:57:25 +01:00
Frediano Ziglio
aa199e6bc6 test-set-ticket: Test we can set the ticket before spice_server_init
Program should not crash.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-03 08:49:20 +01:00
Frediano Ziglio
f77f7d74a1 test-record: Fix a race condition running the test
This could happen if the machine is pretty busy.
I saw intermittent failures on CI and it happened on my
machine also while doing other batch job.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-03 08:48:43 +01:00
Frediano Ziglio
9ea93ab52b spicevmc: Check capabilities of the only possible client
RedVmcChannel can have only one client so check directly it
(the RedChannel version just iterate all clients).
Even if the channel would support multiple clients in this case
we would need to check only the one we are sending the message to.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-01 09:20:00 +01:00
Frediano Ziglio
948ec8b81b dispatcher: Move thread_id field from Dispatcher to MainDispatcher
Dispatcher is just storing the thead_id for MainDispatcher,
move thread_if to MainDispatcher to avoid useless field and API.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-26 14:36:14 +00:00
Frediano Ziglio
137ae60c9a build: Respect Meson's default_library option
Distributions like to be in control of this.
From a patch from  James Le Cuirot.

Instead of always build both shared and static libraries for
SPICE server (static is used for the tests) compile library
as user requested. In case we need the static library for tests
(which now can be disabled) create a static library extracting
objects from shared library.
This also fixes the problem that Meson installed the static
library even if not requested and just used for tests.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2020-03-26 14:35:23 +00:00
Frediano Ziglio
832ab9709c build: Fix a warning for Autoconf
Remove this warning:

server/Makefile.am:5: warning: SUBDIRS was already defined in condition TRUE, which includes condition ENABLE_TESTS ...
server/Makefile.am:2: ... 'SUBDIRS' previously defined here

This was caused by the recent commit 38c7964d53
("build: Make building the test binaries optional under Autoconf")

This problems was also causing some issues as "noinst_PROGRAMS" target
were not compiled as expected.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-26 14:11:38 +00:00
Frediano Ziglio
38c7964d53 build: Make building the test binaries optional under Autoconf
Following similar change for Meson.
Allow to save some time packaging and some dependencies.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-26 09:10:39 +00:00
James Le Cuirot
7a2b915551 build: Make building the test binaries optional under Meson
Signed-off-by: James Le Cuirot <chewi@gentoo.org>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-24 08:38:49 +00:00
Frediano Ziglio
271dd5de41 video-encoder: Use enumeration for encode_frame result type
Better clear the result type instead of a generic "int".

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Kevin Pouget <kpouget@redhat.com>
2020-03-24 08:38:05 +00:00
Victor Toso
4194659c98 sound: default to Opus 48000 Hz
As celt's default 44100 Hz is deprecated.
Related: https://gitlab.freedesktop.org/spice/spice-protocol/-/merge_requests/15

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-17 15:33:23 +00:00
Victor Toso
9136c639a2 sound: remove celt support
Follow up of spice-protocol's deprecation of celt mode.
See: https://gitlab.freedesktop.org/spice/spice-protocol/-/merge_requests/15

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-17 15:33:20 +00:00
Frediano Ziglio
3f851e4f5c red-worker: Fix debugging code
If file was compiled with DEBUG defined code did not compile.
Update code of the surrounded section.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-17 08:18:18 +00:00
Frediano Ziglio
75eaa618a7 dispatcher: Remove some obsolete debugging code
I've never seen used and Dispatcher is quite a code piece of
code, hard to break it.
I also tried to enable and it does not even compile anymore.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-17 08:17:32 +00:00
Frediano Ziglio
cc95067a39 dispatcher: Remove unused "stage" field
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-14 11:53:23 +00:00
Frediano Ziglio
fff6e7da69 smartcard: Avoid useless cast
We just created the object, we know is a RedCharDeviceSmartcard,
avoid to cast the pointer using RED_CHAR_DEVICE_SMARTCARD.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-12 18:57:54 +00:00
Frediano Ziglio
892639a696 inputs-channel: Remove unused macros
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Francesco Giudici <fgiudici@redhat.com>
2020-03-09 13:32:46 +00:00
Frediano Ziglio
b8c1926608 red-common: Remove ring.h inclusion
These structures are not used that extensively, do not include
in the common header.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-04 13:53:32 +00:00
Frediano Ziglio
d1023dc09e red-channel: Remove unneeded ring.h include
Not used in the header.
Also we reduced a lot the usage of these structures.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-04 13:53:30 +00:00
Frediano Ziglio
143c5b290f red-channel: Update some comment and function
red_channel_client_destroy is not called anymore from RedClient and
should not so update the comments.
red_channel_client_destroy, compared to other XXX_destroy functions
did not unreference the object but was just disconnecting the
client channel so use red_channel_client_disconnect instead.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-04 13:53:27 +00:00
Frediano Ziglio
f5aaed38c6 red-client: Do not call red_channel_client_destroy
The object is already destroyed calling red_channel_disconnect_client.
The difference is that red_channel_disconnect_client does it in
the right thread while red_channel_client_destroy here attempts to
do potentially from another thread. This however at this stage
(after already being disconnected) is not an issue, just redundant
and potentially unsafe if red_channel_client_destroy change in
a way to have issue with multiple threads.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-04 13:53:25 +00:00
Frediano Ziglio
5f63e54326 red-channel-client: Remove only set "destroying" field
The field is only set and never checked.
Cascading cleaning up red_channel_client_set_destroying.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-04 13:53:23 +00:00
Frediano Ziglio
b11bb5d7f6 red-channel-client: Remove unused red_channel_client_is_destroying
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-04 13:53:20 +00:00
Frediano Ziglio
53c989a686 spicevmc: Do not call destroy while disconnecting
"RedChannelClient::on_disconnect", which for SpiceVMC is bound to
"spicevmc_red_channel_client_on_disconnect", is called while the
RedChannel object is disconnecting. More precisely is called after
the object has been removed from RedChannel causing
"red_channel_client_is_connected" to be false.
Calling "red_channel_client_destroy" this will lead
to a no-op as function will set "destroying" and call
"red_channel_client_disconnect" which will just exit finding
"red_channel_client_is_connected" false.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-04 13:52:53 +00:00
Frediano Ziglio
c5127b9d0e common-graphics-channel: Use sizeof instead of size constant
Minimal style change.
Allows to easier change the size of the buffer.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Francesco Giudici <fgiudici@redhat.com>
2020-03-04 09:06:17 +00:00
Frediano Ziglio
7230ff3d47 inputs-channel-client: Use sizeof instead of size constant
Minimal style change.
Allows to easier change the size of the buffer.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Francesco Giudici <fgiudici@redhat.com>
2020-03-04 09:04:03 +00:00
Frediano Ziglio
1bf9d22cf2 Support abstract Unix sockets
Allows to specify abstract Unix sockets addresses.
These Unix sockets are supported on Linux and allows to not
have file system names.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Kevin Pouget <kpouget@redhat.com>
2020-03-03 16:18:01 +00:00
Frediano Ziglio
a6ccd2a309 main-channel-client: Set state before sending ping messages
It is not guaranteed that all the messages will be sent on a single
push call, unless this is done very early.
Although currently this function is called very early remove
this hidden assumption in the code.
"ping_id" is just incremented every time a message is sent to
client (in "main_channel_marshall_ping") so the formulae
"mcc->priv->ping_id - 2" was there to get the id of two messages
ago (the first message queued in this function) assuming all
messages were pushed at the time the formulae is used.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2020-03-03 09:26:34 +00:00
Frediano Ziglio
b934b828df Remove "migration-flags" setting to 0
0 is the default value, no need to set explicitly.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-03 08:50:24 +01:00
Frediano Ziglio
594c2feffa Remove "handle-acks" setting to FALSE
FALSE is the default value, no need to set explicitly.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-03 08:50:20 +01:00
Frediano Ziglio
673fbd7147 cursor-channel: Remove unused pipe_item argument from red_marshall_cursor_init
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-03 08:28:56 +01:00
Frediano Ziglio
0f1a606d30 Reuse new spice_extra_assert macro
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-03 08:19:00 +01:00
Frediano Ziglio
4924cf210e reds: Remove only assigned "reds" field
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-03-02 14:24:14 +00:00
Frediano Ziglio
626ad248f5 build: Update spice-common integration
Use new common.m4 include file to make easier to integrate
with spice-common repository.
The new include will allow for instance spice-common to
add additional dependencies without changes (or minor) to
spice-server.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Kevin Pouget <kpouget@redhat.com>
2020-03-02 14:04:06 +00:00
Frediano Ziglio
0fcb6fa4d2 main-channel-client: Remove useless check
main_channel_client_push_ping is never called with mcc NULL.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2020-03-02 07:46:25 +00:00
Frediano Ziglio
99bdb4bddd main-channel-client: Remove unused result from main_channel_client_push_ping
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2020-03-02 07:46:25 +00:00
Frediano Ziglio
0bb564fdca video-stream: Make video_stream*_unref static
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2020-03-02 07:30:23 +00:00
Frediano Ziglio
68c514e1fa reds: Free RedLinkInfo once in reds_handle_link
Instead of freeing it in both reds_handle_main_link and
reds_handle_other_links free it in reds_handle_link.
This will reduce the chances code is changed adding a leak in some paths.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Julien Rope <jrope@redhat.com>
2020-02-29 09:25:25 +00:00
Frediano Ziglio
f338b5bec9 reds: Reuse reds_link_free to free link message
Instead of freeing manually the field and then detaching from
the structure just detach only if retained.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-29 09:09:51 +00:00
Frediano Ziglio
2e1da8486d display-channel: Make display_channel_update_compression static
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-28 13:19:02 +00:00
Frediano Ziglio
4c589e01fb Use local variable to compute gradual score
Due to aliasing using pointers lead to some sub-optimization.
Use local variable and then write them to output to improve performances.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Julien Rope <jrope@redhat.com>
2020-02-27 07:55:43 +00:00
Victor Toso
9e29b72461 red-channel: no need to call g_type_init()
Since 03d46e9e "build-sys: Raise glib requirement to 2.38" in
2019-02-05

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-26 13:01:51 +00:00
Victor Toso
0b1a87a6d0 Remove unused code since glib bump to 2.38
g_assert_null, g_assert_true and g_assert_false are all defined in
GLib 2.38

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-26 13:01:48 +00:00
Victor Toso
e7a2a86779 tests: remove test-glib-compat.c
Basically not run since 03d46e9e "build-sys: Raise glib requirement to
2.38" in 2019-02-05

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-26 13:01:46 +00:00
Victor Toso
7848ee3faf Remove glib-compat.h
Not used since 03d46e9e "build-sys: Raise glib requirement to 2.38" in
2019-02-05

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-26 13:01:43 +00:00
Frediano Ziglio
b939e70d9c red-record-qxl: Write record file in the same format under Windows
The record file uses fprintf to record commands and attributes.
On Windows line terminator uses ASCII format ("\r\n") while on
Linux it used UNIX format ("\n"). Open file as binary to use the
same line terminator on both systems.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Francesco Giudici <fgiudici@redhat.com>
2020-02-26 12:50:27 +00:00
Frediano Ziglio
9bc0aa76f6 red-client: Minor simplification for red_client_get_channel
Remove "ret" variable and just return the value

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Julien Rope <jrope@redhat.com>
2020-02-07 17:52:05 +00:00
Frediano Ziglio
1ce119009a Do not crash if channel clients cannot be created
Channel client creation can fail in some situation.
For instance if during a migration the client is disconnected.
In most cases this is ignored (this is usually logged in
red_channel_client_initable_init) but not in case of
CursorChannelClient and StreamChannelClient.

This fixes rhbz#1788757.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Julien Rope <jrope@redhat.com>
2020-02-07 14:57:36 +00:00
Frediano Ziglio
7026f12c1b reds: Small style change in reds_marshall_migrate_data
Store computed value in a variable to shorten code.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-06 17:42:34 +00:00
Frediano Ziglio
9d9f4946b8 reds: Reuse "sin" variable
reds->vdagent was just set to "sin".

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-01-25 16:59:22 +00:00
Frediano Ziglio
f3a97a001b char-device: Use red_char_device_get_device_instance to retrieve character instance
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-01-24 21:12:39 +00:00
Frediano Ziglio
1e13fb13c7 test-smartcard: Test invalid reader closes the channel
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-01-24 18:31:14 +00:00
Frediano Ziglio
ad94d91017 red-channel-client: Reuse red_channel_client_shutdown
red_channel_client_shutdown remove the watch and shutdown the
socket. Reuse in red_channel_client_disconnect.
Calling shutdown will close the connection earlier.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-01-16 13:54:52 +00:00
Frediano Ziglio
321caf8760 char-device: Add a comment to red_char_device_write_buffer_free
It's a bit surprising that buf is not freed too so explain it.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-01-16 13:47:00 +00:00
Frediano Ziglio
5bcfc2b5d5 char-device: Allow send_msg_to_client callback to be NULL
Mostly of the callback dealing with sent messages and tokens
can be NULL.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-19 12:33:16 +00:00
Frediano Ziglio
8ec691f056 char-device: Allow to more safely and quickly get device instance
This information is retrieved multiple time.
Avoid to use just g_object_get which is dynamic so potentially
unsafe and slow.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-16 15:06:44 +00:00
Frediano Ziglio
5f02dff835 red-client: Automatically set MainChannelClient
This make sure that the RedClient has always an attached
MainChannelClient.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-11 12:47:46 +00:00
Frediano Ziglio
59be4f19c4 red-client: Make sure MainChannelClient is freed as last
MainChannelClient is used by other clients to store some data
so should not disappear if other clients are still present.
Keep a owning reference to it and release after RedClient is
released.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-11 12:47:46 +00:00
Frediano Ziglio
2e1684eb66 red-client: Avoid stale channel client after disconnection
Disconnecting a single channel from the client caused the server to
keep a stale channel client (RedChannelClient object) till the client
(RedClient object) entirely disconnected, that is the channel client
is disconnected but still in the list preventing new connections.
Calling red_client_remove_channel from red_channel_client_disconnect
fixes this last issue.
An issue was that was not clear how the ownership were managed. When
red_client_destroy was called red_channel_client_destroy was called
which freed the RedChannelClient object so this should imply
ownership.
However same red_channel_client_destroy call was attempted by
RedChannel using its list (red_channel_destroy). Basically the two
pointers (the one from the channel and the one from the client) were
considered as one ownership. To avoid the confusion now the client
list always decrement the counter.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-11 12:47:46 +00:00
Frediano Ziglio
f4a387f60d red-client: Protect concurrent list accesses
The channels list was not protected by a lock in red_client_destroy.
This could cause for instance a RedChannelClient object to be
created while scanning the list so potentially modifying the
list while scanning with all race issues.

Consider a client which attempt to connect to a new channel and
then for some reason close the main channel:
- the new channel connection is handled by the main thread;
- the relative RCC will be passed to red_channel_connect which
  can decide to continue the initialization in another thread
  (this happens currently for CursorChannelClient and
  DisplayChannelClient);
- the main thread will catch the main channel disconnection and
  call main_dispatcher_client_disconnect
  (from main_channel_client_on_disconnect);
- main thread calls reds_client_disconnect;
- reds_client_disconnect calls red_client_destroy;
- now we have 2 thread which will attempt to change RedClient::channels
  list, one protected by the mutex the other not.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-11 12:47:41 +00:00
Frediano Ziglio
7887b1bb8e reds: Remove unused mess_pos field
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-06 15:04:18 +00:00
Frediano Ziglio
cff9d951aa red-channel-client: Always enable latency monitor to keep tcp connection alive
Create some traffic on the connection to avoid potential timeout
on some proxies implementation which require some TCP data traffic.
The timeout used by default is quite big (5 minutes) to reduce network
traffic.
In case connectivity monitoring is enabled or latency monitor is
requested the timeout is reduced to the old default.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-12-04 16:28:24 +00:00
Frediano Ziglio
07200c8c1d red-channel-client: Allows to change timeout for latency_monitor
This is a preparatory patch.
The "latency_monitor" feature allows to measure the latency of a
specific channel client.
Currently the measure is attempted every PING_TEST_TIMEOUT_MS which
is a constant.
To be able to use a different frequency allows to change this for every
channel client.
This feature will be also used to create some traffic on the connection
to allows some sort of keep-alive to overcome some proxy implementation
which requires some TCP data traffic.

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

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-12-04 16:28:24 +00:00
Frediano Ziglio
51d94040b2 red-channel-client: Fix typo in comment
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-12-04 12:15:56 +00:00
Frediano Ziglio
2ca660a2f9 stream-channel: Remove default property
"monitor-latency" is FALSE by default.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-12-04 12:15:56 +00:00
Frediano Ziglio
3b9d1eadf7 red-channel-client: Fix indentation
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-12-04 12:15:56 +00:00
Frediano Ziglio
ac41e6097a red-channel-client: Reuse "monitor" variable
"&rcc->priv->connectivity_monitor" is cached in "monitor" variable.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-12-04 12:15:56 +00:00
Frediano Ziglio
0fc5af3a06 Do not check for NULL calling red_watch_remove and red_timer_remove
These functions already check for NULL.
They are used mainly for cleanup, so cold path of code so speed
in case of NULL is not important (and usually should not be NULL).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-12-04 12:15:56 +00:00
Frediano Ziglio
250d4480ff red-channel-client: Reduce indentation in red_channel_client_handle_outgoing
When write fails, all cases of the switch are handled.
Make this clear.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-04 12:15:56 +00:00
Frediano Ziglio
7f501b0df1 ci: Fix a typo in comment
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-11-26 09:22:14 +00:00
Frediano Ziglio
9480df32fe ci: Disable leak error from Valgrind
For some reason under Fedora 31 the g_socket_client_connect call
from test-listen test caused Valgrind to detect a leak.
Note that the like at gtype.c (g_socket_client_connect) specifically
marks a memory block as malloc-like. Not sure if it's an issue
with Valgrind or with GLib, as a workaround disable the leak report.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-11-25 16:58:13 +00:00
Frediano Ziglio
d0614859cf ci: Fix for test-listen leak detection
This suppression was present in former glib.supp version however
the suppression in glib.supp was updated to only catch "reachable"
leaks.
However in test-listen test the allocation is done in a thread
causing the leak to become "definite".

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-11-25 16:58:11 +00:00
Frediano Ziglio
80f16f2f26 ci: Update glib.supp file
Sync with Glib master file.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-11-25 16:58:06 +00:00
Frediano Ziglio
34455d47a9 build: Cleanup old library flags
OpenGL and Slirp requirement were removed much time ago.
OpenGL was removed by c5c176a5c7
(cfr "server: remove OpenGL", Set 2013).
Slirp was removed by ef9a8bf053
(cfr "Remove tunneling support", Oct 2013).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2019-11-25 13:20:18 +00:00
Rosen Penev
1921d57160 reds: Fix compilation without deprecated OpenSSL 1.0.2 APIs
The threading API for 1.0 was replaced with the THREADID API.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-11-06 08:59:13 +00:00
Rosen Penev
5bc932f7a7 reds: Fix compilation without deprecated OpenSSL 1.1 APIs
Missing headers for BN_ and RSA_ functions.

Initialization is deprecated with 1.1.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-11-06 08:59:13 +00:00
Frediano Ziglio
cfdb255b41 smart-channel-client: Remove spicec client reference from comment
spicec is an obsolete client.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-21 09:14:29 +01:00
Frediano Ziglio
5308ab84b9 event-loop: Change internal core interface
Allow to modify/cancel timers/watches without having to retrieve
the code interface.
This will make sure that you are not using the wrong interface.
Simplify code to deal with timers/watches.
Remove the requirement to have the core interface available
for removing timers/watches.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-10 10:55:52 +01:00
Frediano Ziglio
97d2d1f129 event-loop: Move adapter interface from reds.c
Put more event loop code in event-loop.c.
This is a preparation patch for the next one.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-10 10:55:38 +01:00
Frediano Ziglio
ebe676697f smartcard: Reset vheader value
The buffer could change inside smartcard_read_buf_prepare.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-10 10:51:59 +01:00
Frediano Ziglio
60a61be549 smartcard: Fix statement termination
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-10 10:51:48 +01:00
Frediano Ziglio
d8d5c48ad6 test-smardcard: Improve test coverage
Using coverage utility exercise more code paths:
- message from channel with wrong type;
- remove message from channel with already removed reader;
- init message from channel (ignored);
- data from devices, ADPU;
- error from device;
- messages split in different ways;
- invalid reader_id values.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-09 10:33:25 +01:00
Frediano Ziglio
344ce666cf test-smartcard: Add test for Smartcard device
Create Smardcard device.
Connect to it and test some messages are parsed and processed
as expected.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-09 10:33:25 +01:00
Frediano Ziglio
b4e508880a test-stream-device: Factor out VMC emulation
Allows to reuse code for emulating a character device.
It will be used for Smardcard test.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-09 10:33:25 +01:00
Frediano Ziglio
07d9328f89 smartcard: Fix parsing multiple messages from the device
This patch handles the scenario when a single read to guest device
brings multiple requests to be handled. When this happens, we will
iterate till all requests are handled and no more requests can be read
from guest device.

If the remaining buffer contains a full request we don't need to read
other bytes (note that there could be no bytes left), just parse the
request.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-09 10:33:22 +01:00
Frediano Ziglio
6fa12db104 smartcard: Fix copying remaining request
Use memmove instead of memcpy as the buffer can overlap if the second
request if bigger than the first.
"buf_pos" points to the point of the buffer after we read, if we want
the first part of the next request is "buf_pos - remaining".
Same consideration setting "buf_pos" for the next iteration.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-09 10:33:17 +01:00
Frediano Ziglio
57d02c2d17 smartcard: Do not crash if reader_id is invalid
Avoid client to trigger crash. The value of smartcard_readers_get
is checked for NULL so returning it it's not an issue.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-09 08:53:10 +01:00
Frediano Ziglio
18877d1af8 smartcard-channel-client: Use log instead of printf
More coherent. Also it's not good for a library to output on
standard output.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-09 08:53:06 +01:00
Frediano Ziglio
8d4d4e3a39 smartcard-channel-client: Remove properties code
Not used

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-09 08:45:25 +01:00
Frediano Ziglio
d546696424 red-channel-client: Use SpiceMsgcAckSync structure
red_channel_client_handle_message is called after parsing the
message so it's not necessary to check it again or parse manually.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-08 17:12:59 +01:00
Frediano Ziglio
2b56398c34 red-channel-client: Remove useless check
Message is checked by generated message parser.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-08 17:12:59 +01:00
Frediano Ziglio
774d466cf8 red-channel: Make parser function compulsory
As base messages require parsing better channels should always use
the generated parser.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-08 17:12:59 +01:00
Frediano Ziglio
bae2d1f00f smartcard: Use generated parse for messages
The generated code handle possible endianess mismatch and check
for message format.
The copy back to "write_buf" allows to use that buffer to send
data back to device.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-08 16:01:56 +01:00
Frediano Ziglio
33d81bc3fa smartcard-channel-client: Remove unused parameter
"name" parameter of smartcard_channel_client_add_reader it's not
used.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-08 15:34:14 +01:00
Frediano Ziglio
abbd985c78 spicevmc: Fix g_object_new call for 32 bit machines
"self-tokens" property is 64 bit and must be passed as 64 bit on
32 bit machines to avoid memory corruptions.
This was introduced by 01de3b8922 ("spicevmc: Avoids DoS if
guest device is not able to get data faster enough"), detected by CI.

It caused this error (split into multiple lines):

  (./test-leaks:15879): GLib-GObject-CRITICAL **: 14:03:59.650: \
  g_object_new_is_valid_property: object class 'RedCharDeviceSpiceVmc' has \
  no property named '\xb0/@\xf3\u0001'

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-09-24 16:22:46 +01:00
Frediano Ziglio
01de3b8922 spicevmc: Avoids DoS if guest device is not able to get data faster enough
This fix half (one direction) of
https://gitlab.freedesktop.org/spice/spice/issues/29.
Specifically if you have attempt to transfer a file from the client
using WebDAV.
Previously the queue to the device was unbound. If device was not
getting data fast enough the server started queuing data.
To easily test this you can suspend the WebDAV daemon while transferring
a big file from the client.
To simplify the code and reduce the changes server buffers are
used. This as client token implementation is written with agent
in mind. While when we exhaust server tokens RedCharDevice doesn't
close the client when we exhaust client tokens RedCharDevice closes
the client which in this case it's not wanted.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-09-24 13:38:01 +01:00
Frediano Ziglio
726b1824e3 red-channel-client: Allows to block receiving data
If the client is keeping sending data while we can't handle them
(for instance because we need to forward to a device but the
device is not fast enough to receive that amount of data) allows
to stop RedChannelClient to read data.
This after a bit will stop the client sending data as its output
buffer will become full.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-09-24 13:37:55 +01:00
Frediano Ziglio
1157588cc1 spicevmc: Avoids DoS if client is not able to get data faster enough
This fix half (one direction) of
https://gitlab.freedesktop.org/spice/spice/issues/29.
Specifically if you have attempt to transfer a file to the client
using WebDAV.
Previously the queue to the client was unbound. If client was not
getting data fast enough the server started queuing data.
To easily test this you can use a tool to limit bandwidth and
transfer a big file (I used a "dd if=/dev/zero bs=1M of=test") from
the guest.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-09-24 13:12:58 +01:00
Frediano Ziglio
540f70351d spicevmc: Do not use RedCharDevice pipe items handling
As we don't use any token there's no reason to not queue directly instead
of passing through RedCharDevice.
This will make easier to limit the queue which currently is unlimited.

RedCharDevice flow control has some problems:
- it's really designed with VDI in mind. This for SpiceVMC would cause
  code implementation to be confusing having to satisfy the agent token
  handling;
- it's using items as unit not allowing counting bytes;
- it duplicates some queue management between RedChannelClient;
- it's broken (see comments in char-device.h);
- it forces "clients" to behave in some way not altering for instance the
  queued items (which is very useful if items can be collapsed together);
- it replicates the token handling on the device queue too. This could
  seems right but is not that if you have a network card going @ 1 GBit/s
  you are able to upload more than 1 Gbit/s just using multiple
  connections. The kernel will use a single queue for the network interface
  limiting and sharing de facto the various buffers between the multiple
  connections.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-09-24 13:12:52 +01:00
Victor Toso
c83420feae main-channel-client: style fixup, indentation of return
Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-09-24 09:46:13 +02:00
Frediano Ziglio
4f2d90a784 red-qxl: Make sure we have at least one monitor
It does not make sense to have a graphic card without a monitor.
In spice_qxl_set_max_monitors we prevent to set 0 monitors, do
the same in spice_qxl_set_device_info.

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

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Tested-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-09-19 14:54:53 +01:00
Frediano Ziglio
b862bee93f smartcard: Use RedChannelClient as the type for RedCharDevice client
As now is an opaque type for RedCharDevice use the type that
better suits us.
This avoid useless conversions or look ups.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-09-17 12:17:31 +01:00
Frediano Ziglio
14fe2c3766 char-device: Don't use RedClient API
RedClient was an opaque structure for RedCharDevice.
It started to be used when RedsState started to contain all
the global state.
Make it opaque again using a new RedCharDeviceClientOpaque.
The RedCharDeviceClientOpaque define in the header allows users
of the class to override the type to get a more safe type
than RedClient.
The define at the beginning of C file is to make sure we don't
use the opaque type as a specific one.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-09-17 12:17:26 +01:00
Frediano Ziglio
6ccf0e4800 red-channel-client: Inline red_channel_client_get_channel in macro
Inline red_channel_client_get_channel in spice_channel_client_error
macro.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-09-17 09:40:29 +01:00
Frediano Ziglio
609398fb77 reds: Inline reds_mig_switch function
No much reason for not inlining it, it's quite small and do
not reduce readability.
Note that spice_server_migrate_switch is deprecated and not
used by Qemu since commit 67be6726b6459472103ee87ceaf2e8e97c154965
(cfr "spice: raise requirement to 0.12" September 2012).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-09-17 09:40:24 +01:00
Frediano Ziglio
2d425ee6ae reds: Fix indentation of spice_server_char_device_add_interface
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-09-02 10:52:09 +01:00
Kevin Pouget
9ccf7bee7a stream-channel: Add preferred video codec capability
This patch enables the SPICE_DISPLAY_CAP_PREF_VIDEO_CODEC_TYPE
capability for the stream-channel.

video_stream_parse_preferred_codecs: new function for parsing the
SPICE protocol message. This code used to in inside
dcc_handle_preferred_video_codec_type.

struct StreamChannelClient::client_preferred_video_codecs: new field.

Signed-off-by: Kevin Pouget <kpouget@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-09-02 09:53:27 +01:00
Uri Lublin
a9d53f3cd1 test-loop: increment a variable outside of spice_assert
spice_assert is a macro and covscan reports that:
  Argument "++twice_remove_called" of spice_assert() has a side effect.

Doesn't matter if there is a side effects or not,
it's a good practice and it makes covscan happy, so
increment the variable one line above.

Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-08-22 21:27:35 +01:00
Uri Lublin
e9c8b25904 valgrind/spice.supp: add missing ...
There may to be another function (cache_alt_names) between
  gnutls_x509_ext_import_subject_alt_names and
  gnutls_x509_crt_import

cache_alt_names is a static function in gnutls/lib/x509/x509.c
used only in gnutls_x509_crt_import and may be inlined by
the compiler.

Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-08-22 08:54:00 +01:00
Frediano Ziglio
80bb7eb774 stat-file: Use proper macro for container computation
This is currently more style patch as the "value" field is the
first field of SpiceStatNode structure, so has offset 0. However
to compute the containing structure it better to use the proper
macro to avoid confusion.
If the offset won't be 0 the subtraction would compute the
wrong pointer as the offset is expressed in bytes but the
element size are uint64_t.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-22 08:53:23 +01:00
Frediano Ziglio
85461f59cc Remove reference to removed ABI
spice_server_migrate_client_state was removed by

  commit 3c6b4e415f
  Author: Marc-André Lureau <marcandre.lureau@gmail.com>
  Date:   Fri Oct 24 17:16:35 2014 +0200

    Remove spice-experimental

    Remove unneded symbols that nobody should be using anyway.
    ABI is modified with this patch, but the library version is not bumped.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-08-15 11:16:42 +01:00
Frediano Ziglio
461288534f glz-encode: Remove obsolete reference segment
The GLZ code is basically LZ code (in spice-common) sharing image
segments between multiple images.
The code for RLE check in LZ (common/lz_compress_tmpl.c) is dealing
with both RLE and dictionary matches being:

    if (!distance) {
        /* zero distance means a run */
        PIXEL x = *ref;
        while ((ip < ip_bound) && (ref < ref_limit)) { // TODO: maybe separate a run from
                                                       //       the same seg or from different
                                                       //       ones in order to spare
                                                       //       ref < ref_limit

in GLZ that part was copied to RLE part removing the need for the
second segment ("ref"). However the comment and setting ref variables
were not removed. Remove the old code to avoid confusions.

This also remove a Covscan warning as ref_limit was set not not used
(reported by Uri Lublin).
The warning was:

CLANG warning: "Value stored to 'ref_limit' is never read"

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-08-12 10:48:02 +01:00
Frediano Ziglio
2f6e2a8ef9 Use (u)intptr_t for virtual addresses
On LLP64 platforms (like Windows) a virtual address cannot be
represented by a "unsigned long" type, so use uintptr_t which is
defined as an integral type large like a pointer.
"address_delta" and "addr_delta" are a difference of pointers so use
same type size.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2019-08-12 08:16:31 +01:00
Frediano Ziglio
c289a6eee3 red-replay-qxl: Fix replay on 32 bit systems
On 32 systems pointers are 32 bit while QXLPHYSICAL is always
64 bit.
Using pointer -> intptr_t -> QXLPHYSICAL conversion cause pointers
to have higher 32 bit set to 1 if the address is >= 0x80000000.
This is possible depending on address space.
The QXLPHYSICAL is split in 3 sections:
- slot ID;
- generation;
- virtual address.
Current utility using record file (spice-server-replay) set slot ID
and generation to 0 so if the higher bits become all 1 slot ID and
generation won't be 0 causing the utility to fail.
Use pointer -> uintptr_t -> QXLPHYSICAL conversion to avoid this
issue.
Note that for opposite conversion (QXLPHYSICAL_TO_PTR) the conversion
does not change, type is changed just for consistency.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2019-08-11 10:18:11 +01:00
Frediano Ziglio
3ebc6d4a43 replay: Remove some leak and a FIXME
Threads are joined by spice_server_destroy, just need to release
last resources.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2019-08-11 10:10:35 +01:00
Frediano Ziglio
3af64b61dc replay: Remove some goto statement
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2019-08-11 10:10:30 +01:00
Frediano Ziglio
32ee52df16 test-websocket: Reuse red_socket_set_non_blocking
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-08-06 13:45:24 +01:00
Frediano Ziglio
5f62d03073 test-websocket: Some Windows compatibility
Don't call close but socket_close.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-08-06 13:45:04 +01:00
Frediano Ziglio
f584a5d6b6 char-device: Allocate all write buffer in a single block
There are no much data other than the buffer, reduce the
allocations.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 11:57:24 +01:00
Frediano Ziglio
cee05ca8ac red-channel-client: Add some comment on the flush code
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>,
2019-08-02 11:27:44 +01:00
Frediano Ziglio
2e357a9b7b red-channel-client: Reduce indentation of some code
Just a style change, return earlier to avoid some indentation.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 11:26:33 +01:00
Frediano Ziglio
5fb4f52bdb dispatcher: Use a new API to handle events
Instead of having to manually register the file descriptor and
than need to call dispatcher_handle_recv_read just provide a single
API to create the watch.
This has some advantage:
- replace 2 API with 1;
- code reuse for handling the event (removed 2 functions);
- avoid the caller to use the file descriptor;
- avoid the caller to register wrong events.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 11:16:57 +01:00
Frediano Ziglio
a21de34173 char-device: Pull more code into red_char_device_send_to_client_tokens_absorb
The 2 callers red_char_device_send_to_client_tokens_set and
red_char_device_send_to_client_tokens_add are doing mostly
the same thing so put common code to
red_char_device_send_to_client_tokens_absorb.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 11:14:16 +01:00
Frediano Ziglio
314c57c233 red-channel: Inline red_channel_pipes_create_batch
The function is called only by red_channel_pipes_new_add.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 11:11:05 +01:00
Frediano Ziglio
2160b1ea39 spicevmc: Remove reds parameter from spicevmc_device_disconnect
Unused.
Also the devices should be able to release themselves.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 10:59:00 +01:00
Frediano Ziglio
67c7dacd07 red-worker: Remove warning
In some configuration _GNU_SOURCE is defined by the compiler
and defining again cause a warning.
Do not define again to avoid the warning.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 10:58:31 +01:00
Frediano Ziglio
75879867b7 char-device: Remove unused red_char_device_destroy function
g_object_unref is directly used.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 10:57:07 +01:00
Frediano Ziglio
b22ce8b042 glz-encoder: Remove useless __packed__ attribute
These structure contain only bytes, no need for this attribute.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 10:55:27 +01:00
Frediano Ziglio
ecd0d70a3d glz-encoder-dict: Remove useless __packed__ attribute
The structure has no holes, adding this attribute could only
decrease efficiency.
Note that HashEntry structure is used for a large (8MB) array so
this won't affect much possible container size.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-08-02 10:55:20 +01:00
Frediano Ziglio
db7dcae353 red-parse-qxl: Fix QUIC images from QXL
The decoding is wrong, the Red and QXL structures are different so
code is not doing what is expected. red-parse-qxl translate from QXL
to Red structures, red-record-qxl saves Red structure to file,
red-replay-qxl is supposed to read from file into QXL directly.

If a Quic image is stored inside QXL memory the layout of the QXLImage
in memory is:
- QXLImageDescriptor
- QXLQUICData
- QXLDataChunk
- first chunk data
and all remaining data in linked QXLDataChunk.
red_replay_image was reading the image as data was all contained in
QXLImage->quic.data however "data" should store the first QXLDataChunk
followed by QXLDataChunk data.
Use proper base_size calling red_replay_data_chunks in order to
initialise the image with the first data chunk correctly.

Not easy to reproduce, the only driver is XDDM which means Windows XP
or similars. To enable QUIC encoding I added "image-compression=quic"
and "streaming-video=off" to "-spice" Qemu option in order to force
QUIC encoding in the guest driver (thanks to Uri Lublin for the help
reproducing it).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-07-31 16:29:13 +01:00
Frediano Ziglio
6c1e2c412f event loop: improve implementation of watches for Unix systems
Avoid having to destroy and create a new GSource every time
we change event mask.
Interfaces required for this patch are available since GLib 2.36
and are specific to Unix.
On Windows use old implementation.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-07-24 11:19:38 +01:00
Frediano Ziglio
21ec1369a3 red-replay-qxl: Fix some issue of alignment
Do not pass unaligned QXLPHYSICAL but pass a valid pointer and
then cast.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-07-22 16:32:23 +01:00
Frediano Ziglio
6ddd8b0b36 Use start/end-packet.h headers instead of direct GCC attribute
All other code use these headers.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2019-07-22 14:56:00 +01:00
Uri Lublin
ec5f9b008f tests: rename video-encoders to test-video-encoders
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-07-22 11:21:23 +01:00
Frediano Ziglio
2ababd6177 ci: Add some Valgrind suppressions for Fedora 30
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-07-18 15:56:07 +01:00
Frediano Ziglio
d2979e23e9 ci: Update glib.supp file
Sync with Glib master file.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-07-18 15:56:07 +01:00
Frediano Ziglio
911455ba65 ci: Separate SPICE specific Valgrind suppression
Previously we add suppression to glib.supp file (suppressions from
Glib).
Keep the glib.supp file pristine and add another file specific
for SPICE.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-07-18 15:56:07 +01:00
Frediano Ziglio
642b1683ae websocket: Include proper type header
inttypes.h contains macro for format string while
stdint.h more specifically contains type definitions (like uint8_t).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-07-17 12:53:11 +01:00
Frediano Ziglio
4894d58ace reds: Fix use-after-free
video_codecs can be freed so use it before.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-07-17 12:53:11 +01:00
Uri Lublin
81c90b54b5 gst:mjpeg do not set max-threads
1. It was renamed in newer versions to 'threads'
2. The default is 1 anyway

Signed-off-by: Snir Sheriber <ssheribe@redhat.com>
Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-07-17 11:21:55 +01:00
Frediano Ziglio
705ae9c197 websocket: Make header self-independent
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-07-16 15:42:49 +01:00
Frediano Ziglio
3a8c0bc28d websocket: Add header guards
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-07-16 15:42:32 +01:00
Uri Lublin
da162ad411 dcc-send: fix use-after-free
'l' is being freed within the loop

Found-by: Frediano Ziglio <fziglio@redhat.com>
Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-07-11 09:37:34 +01:00
Frediano Ziglio
636f9c25a6 dcc-send: remove unused variable 'image'
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-07-11 09:37:20 +01:00
Uri Lublin
44325e1154 dcc-send: remove useless pipe_item assignment pipe_item
In red_pipe_replace_rendered_drawables_with_images, the
value of pipe_item is re-written on the next iteration.

Since a78a7d2510 pipe_item
is no longer used to control the loop.

Found by Covscan.

Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-07-11 09:37:17 +01:00
Kevin Pouget
4000846c01 streaming: Restart streams on video-codec changes
Interrupt the video streams when the user changes the preferred
video-codecs (dcc_handle_preferred_video_codec_type) or when the host
admin updates the list of video-codecs allowed
(display_channel_set_video_codecs).

The video streaming will be automatically restarted by spice
video-detection rules.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-07-11 09:28:51 +01:00
Frediano Ziglio
3e299cede8 spice-char: Add some documentation to SpiceCharDeviceInterface
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-07-10 09:53:58 +01:00
Frediano Ziglio
a0497f0407 red-common: Add a comment for GLIST_FOREACH_GENERIC
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-07-09 11:10:27 +01:00
Frediano Ziglio
4f5c342eea red-qxl: Better encapsulation of device display information
Do not expose multiple functions to fetch different parts of
internal structure.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2019-07-08 13:19:12 +01:00
Frediano Ziglio
fdf104fe28 test-codecs-parsing: On bad codec string spice_server_set_video_codecs can fail
The 0 result means success however the function (correctly) could
report a failure if the string is incorrect.
This fixes the test after commit b4150de3cd
("spice_server_set_video_codecs: fail when no codec can be installed").

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com
2019-07-08 08:15:36 +01:00
Kevin Pouget
b4150de3cd reds: spice_server_set_video_codecs: fail when no codec can be installed
Public function spice_server_set_video_codecs: return -1 if no
encoder/codec has been installed, instead of always returning 0.

Internal function reds_set_video_codecs_from_string: return the number
of invalid encoder/codec entries found in the input list, and update
the installed pointer with the number of encoder/codec pairs
successfully installed.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-07-05 13:36:12 +01:00
Kevin Pouget
321c5cb7f6 reds: Add ability to query the video-codecs currently enabled
spice_server_get_video_codecs: new public function to query the video
encoders/codecs currently enabled in the spice server. It returns a
string that can be fed to the setter counter
(spice_server_set_video_codecs). The string returned by this function
should be released with spice_server_free_video_codecs.

spice_server_free_video_codecs: new public function to free the the
video codec list returned by spice_server_get_video_codecs.

video_codecs_to_string: new private function to transform an array of
RedVideoCodec into a string.

Signed-off-by: Kevin Pouget <kpouget@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-07-05 11:11:57 +01:00
Uri Lublin
c964ca4040 typo: fix the spelling of precede
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-07-04 10:05:19 +01:00
Uri Lublin
44d6d587b0 typo: image-encoders: fix the spelling of guaranteed
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-07-04 10:05:16 +01:00
Uri Lublin
8c510901dd typo: dcc: fix the spelling of unknown
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-07-04 10:05:13 +01:00
Kevin Pouget
48ab22b728 gstreamer-encoder: fix compiler warning with Fedora 30
Fedora 30 / gcc 9.1.1 20190503 (Red Hat 9.1.1-1) fails to build
because of this error/warning:

> gstreamer-encoder.c: In function 'set_video_bit_rate':
> gstreamer-encoder.c:518:17: error: taking the absolute value of
> unsigned type 'uint64_t' {aka 'long unsigned int'} has no effect
> [-Werror=absolute-value]
>  518 |     } else  if (abs(bit_rate - encoder->video_bit_rate) > encoder->video_bit_rate * SPICE_GST_VIDEO_BITRATE_MARGIN) {
>      |                 ^~~
> gstreamer-encoder.c:518:17: error: absolute value function 'abs'
> given an argument of type 'uint64_t' {aka 'long unsigned int'}

This patches solves these two warnings:

1) cast the substraction to a signed type (int64_t instead of
uint64_t) to preserve the operation meaning;

2) use a custom version of abs() to avoid data truncation and/or
platform-dependent type lengths (abs/labs/llabs)

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-07-03 14:24:25 +01:00
Francois Gouget
2bb96f105d utils: Make all the NSEC_PER_XXX constants 64 bit
Code dealing with nanosecond timestamps normally uses 64 bit integers
and not long long ints. So this makes it easier to print the value of
expressions using these constants.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-07-03 12:08:50 +01:00
Frediano Ziglio
94611ac175 red-parse-qxl: Reset mask attributes if brush image is missing
The attributes in this case are not used to apply the mask.
Doing so avoid sending garbage from the guest which usually
don't initialise the memory in case the mask is missing.
Guest should have cleared these bytes by its own however doing so
on the server fixes the problem too. Considering that these
command should not appears in newer OSes it's surely not a hot path
code.
These garbage came from video memory of the guest so they don't
contain sensitive data.

This fixes https://gitlab.freedesktop.org/spice/spice-server/issues/25.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2019-07-02 13:47:18 +01:00
Frediano Ziglio
2dae4de360 display-channel: Initialize priv as soon as possible
This avoid potentially memory errors while setting properties.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-06-27 11:52:51 +01:00
Frediano Ziglio
7eb321c1bb display-channel: Remove some useless function declarations
"image_surfaces_get" and "drawables_init" are already defined
in the same file earlier.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-06-27 10:52:50 +01:00
Frediano Ziglio
a68fd56b41 ci: Add test for websockets
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:19:43 +01:00
Frediano Ziglio
c1c5d8bf5a websocket: Handle continuation and 0-size frames
The WebSocket protocol allows 0-size frames so a returned lenth of
0 does not only mean an issue but it's perfectly expected.
This is also required by WebSocket specification.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:19:13 +01:00
Frediano Ziglio
9d6a438aae websocket: Handle text data
Allows to specify and get frame type.
Type and flags are returned calling websocket_read and returned
calling websocket_write or websocket_writev.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:19:10 +01:00
Frediano Ziglio
0c7f91511d websocket: Do not require "Sec-WebSocket-Protocol" header
Not strictly needed, client can work even without specifying
that.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:19:07 +01:00
Frediano Ziglio
975d444f21 test-websocket: Write a test helper to make possible to run Autobahn testsuite
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:19:05 +01:00
Frediano Ziglio
62582df789 websocket: Handle PING and PONG frames
Websocket implementations are required to implement such messages.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:19:02 +01:00
Frediano Ziglio
5a352c1823 websocket: Avoids to write close frame in the middle of data
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:59 +01:00
Frediano Ziglio
b5a622df76 websocket: Handle case if server cannot write the header entirely
Quite rare case, can only happen with congestion, buffers very low
and some space left in the former packet.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:57 +01:00
Frediano Ziglio
2ba66599c1 websocket: Support correctly protocol values
Ignore spaces before "binary" value.
HTTP allows space before and after the value although usually
browsers implementation start the value with a single ASCII space.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:55 +01:00
Frediano Ziglio
39a791a964 websocket: Avoid possible server crash using websockets
Currently code don't handle if system can't sent the
header in a single write command.
Don't cause abort but just close the connection.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:53 +01:00
Frediano Ziglio
0c2f386beb websocket: Fix updating remaining bytes to write in websocket_write
"len" is not always the full remainder (consider the case when
we are writing a partial frame).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:50 +01:00
Frediano Ziglio
9f1417c11f websocket: Propagate some variable
These were introduced moving code around.
No more reason to copy, just use directly structure fields.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:48 +01:00
Frediano Ziglio
6b41f3b542 websocket: Better variable types
"type" is just 8 bit.
"frame_ready" and "masked" as booleans.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:46 +01:00
Frediano Ziglio
007e009bc3 websocket: Detect and handle some header error
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:43 +01:00
Frediano Ziglio
55df5fa841 websocket: Better encapsulation
Move websocket structure declarations to C file.
Make some functions static as now not used externally.
Introduce a websocket_free function for symmetry.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:40 +01:00
Frediano Ziglio
a5c05ad845 websocket: New interface to create RedsWebSocket
Less coupling. This is a preparation for next patch.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:38 +01:00
Frediano Ziglio
b5f3ed1502 websocket: Make websocket_ack_close static
It's used only in websocket.c.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:36 +01:00
Frediano Ziglio
bbfb472154 websocket: Make websocket function more ABI compatibles with RedStream
Use same argument types as red_stream_* functions.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:33 +01:00
Frediano Ziglio
98c183a6f6 websocket: Move RedsWebSocket to header
Intention is to make private in websockets.c and reduce
changes in red-stream.c

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:31 +01:00
Frediano Ziglio
26fad876a0 websocket: Simplify and fix constrain_iov
Use g_memdup instead of manual copy.
Trim the original iov if necessary.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:29 +01:00
Jeremy White
cd2a317096 Add support for clients connecting with the WebSocket protocol.
We do this by auto detecting the inbound http(s) 'GET' and probing
for a well formulated WebSocket binary connection, such as used
by the spice-html5 client.  If detected, we implement a set of
cover functions that abstract the read/write/writev functions,
in a fashion similar to the SASL implementation.

This includes a limited implementation of the WebSocket protocol,
sufficient for our purposes.

Signed-off-by: Jeremy White <jwhite@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-06-26 14:18:27 +01:00
Frediano Ziglio
214736dce6 reds: Fix SSL_CTX_set_ecdh_auto call for some old OpenSSL
SSL_CTX_set_ecdh_auto is not defined in some old versions of OpenSSL

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:25 +01:00
Frediano Ziglio
89b0a07c72 test-glib-compat: Fix G_PID_FORMAT definition for old systems
The G_PID_FORMAT constant is defined only if GLib does not support it.
The constant was wrongly defined.
Jessie Debian 32 shows this issue (printf format error).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jeremy White <jwhite@codeweavers.com>
2019-06-26 14:18:17 +01:00
Frediano Ziglio
11b0a58bbf dcc-send: Check some constants at compile time
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-06-24 09:41:35 +01:00
Frediano Ziglio
fce721cbe7 cache-item: Remove unused define
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-06-21 08:30:56 +01:00
Frediano Ziglio
94e1d52ff6 cache-item: Remove only written fields
cursor_cache_items and palette_cache_items where only written
but never used.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-06-21 08:30:56 +01:00
Frediano Ziglio
bf968572d1 display-channel: Avoid potential crash from buggy guest driver
This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1582137.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2019-06-20 09:57:09 +01:00
Frediano Ziglio
1a3c0b1ee6 jpeg: Support big endian machines
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-06-19 10:36:10 +01:00
Frediano Ziglio
6412760873 Remove a warning on MIPS machine
The formula is here to make sure glyph is aligned to 4 bytes so
tell to the compiler to avoid a warning.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-06-19 10:30:06 +01:00
Frediano Ziglio
47cbfd4c59 Use SPICE_CONTAINEROF to avoid some possible alignment warnings on MIPS
This patch came from some experiments using an emulated MIPS machine.
On such architecture due to not supporting alignment access the
compiler is more strict about conversion complaining with some
pointer casts. Use different conversion to avoid these warnings.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-06-18 09:48:28 +01:00
Frediano Ziglio
f90f75e41c red-stream: Fix compilation on Fedora 30 for Windows using MingW
On Windows Fedora 30 reports these errors:

In file included from /usr/x86_64-w64-mingw32/sys-root/mingw/include/openssl/crypto.h:29,
                 from /usr/x86_64-w64-mingw32/sys-root/mingw/include/openssl/bio.h:20,
                 from /usr/x86_64-w64-mingw32/sys-root/mingw/include/openssl/err.h:21,
                 from red-stream.c:31:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/openssl/x509.h:75:1: error: pasting "stack_st_" and "(" does not give a valid preprocessing token
 DEFINE_STACK_OF(X509_NAME)
 ^~~~~~~~~~~~~~~
/usr/x86_64-w64-mingw32/sys-root/mingw/include/openssl/x509.h:75:17: error: expected ')' before numeric constant
 DEFINE_STACK_OF(X509_NAME)
                 ^~~~~~~~~
...

This is due to missing X509_NAME definition by Windows headers.
Including the network header on Windows solves this problem.
This is consistent with reds.c file.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-06-13 12:53:37 +01:00
Frediano Ziglio
0002d1a93c Remove compile warnings on Linux 32bit system
Based on a patch from Hongzhi.Song <hongzhi.song@windriver.com>.

There are following compile errors on Linux 32bit system with -Werror
for gcc.

red-channel.c:207:73: error: format '%x' expects argument of type
'unsigned int', but argument 7 has type 'long unsigned int' [-Werror=format=]
|207| red_channel_debug(self, "thread_id 0x%" G_GSIZE_MODIFIER "x",
				~~~~~~~~~~~~~~~~~~~~~^
			self->priv->thread_id);
		~~~~~~~~~~~~~~~~~~~~~^

pthread_t is an opaque type so there is no easy way to make the printf
format string portable. However the type must be comparable in C so this
(excluding floating point which does not make sense) means an integral type
or a pointer.
Under *BSD this is a pointer so can be converted without loosing precision
to void*.
Under Linux this is a "unsigned long int" type, being Linux ILP32 or LP64
this means that the size of pthread_t is the same as size_t so can be
converted without loosing precision to void*.
Under MingW (the pthread port to Windows) this is a uintptr_t type that is
can be converted without loosing precision to void*.
On any potential future platforms if the integral type is smaller than a
uintptr_t type (which has the same size of void*) the cast should trigger a
warning and if not won't loose precision; the integral type is unlikely to
be bigger than a pointer and likely the cast would trigger a warning.

The cast on read_binary (red-replay-qxl.c) is safe, "*size" is a size_t
while "strm.total_out" is the number of written bytes in a buffer which
cannot be bigger than a size_t.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-06-13 09:04:01 +01:00
Frediano Ziglio
789e8ce2c6 red-channel: Remove unused declaration
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-06-13 07:44:10 +01:00
Frediano Ziglio
4235121f52 inputs-channel-client: Remove unused declarations
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-06-13 07:44:10 +01:00
Frediano Ziglio
d623b275bd smartcard-channel-client: Fix some typos in a comment
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-06-13 07:38:50 +01:00
Christian Ehrhardt
19f9f454e0 test: fix test-qxl-parsing on ppc64el and armhf
On ppc64el and armhf the handling of "1 << mem_info.memslot_id_shift"
will end up beign a zero which breaks the test.

Marking the implicit value 1 as a 64 bit value (to match the uint64_t
target) fixes the issue.

Fixes #31

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-06-12 14:47:15 +01:00
Francois Gouget
d4251bac5f utils: Remove the LL suffix from NSEC_PER_MILLISEC
This constant fits in a regular 32 bit signed integer so it does not
need the suffix.
It is also not used in expressions that may overflow.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-06-12 10:16:12 +01:00
Francois Gouget
476f19a3c8 gstreamer-encoder: Document get_maximum_frame_size()
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-06-12 10:09:54 +01:00
Frediano Ziglio
581a2d0f68 char-device: Reuse macros to scan GList
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-06-10 13:44:07 +01:00
Frediano Ziglio
e624795747 common-graphics-channel: Avoid closing server if client send huge messages
The Cursor/DisplayChannel is not expecting large messages (which are
protocol violations).

This fixes https://gitlab.freedesktop.org/spice/spice-server/issues/11.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-06-10 13:44:01 +01:00
Frediano Ziglio
a84d9c653e spicevmc: Reuse "sin" variable
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2019-06-02 14:46:08 +03:00
Frediano Ziglio
a9af580a6e char-device: Fix some comments
Some function names where changed.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2019-06-02 14:44:58 +03:00
worldofpeace
b4a6c1abcc meson: correct some things
We can get source_root from meson, and doing [3]
can give you an out of bounds error in certain cases.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-05-29 13:14:24 +01:00
Francois Gouget
3d7f1cc512 mjpeg: Pull more code in get_min_required_playback_delay()
This reduces code duplication and passing the MJpegEncoder object
makes it possible to modify the playback calculation without adding
more arguments.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-05-21 09:05:50 +01:00
Francois Gouget
7515a0ac57 mjpeg: Constify some MJpegEncoder* parameters
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-05-21 09:05:47 +01:00
Francois Gouget
a8faddf653 gstreamer-encoder: Constify some SpiceGstEncoder* parameters
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-05-21 08:51:53 +01:00
Francois Gouget
ba4bcd5174 gstreamer-encoder: Return the average frame size as a 32 bit int
It makes no sense to expect average frame sizes anywhere close to 2GB.
But then make sure to avoid arithmetic overflows.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-05-21 08:48:49 +01:00
Francois Gouget
cfe98800a0 gstreamer-encoder: Show the source fps when the system is too slow
The source framerate is as important as the resolution when trying to
understand if the system should be fast enough to encode the video
stream in real time.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-05-21 08:46:27 +01:00
Frediano Ziglio
148203a5d2 spice-experimental: Remove obsolete file
This header was removed in 2014 (3c6b4e415) as deprecated and added again
in 2015 (2e88eb705) as causing some issue with former Qemu versions.
After 4 years remove again, now there should not be any usage of it.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2019-05-20 10:11:41 +01:00
Francois Gouget
5ee001a5b0 gstreamer-encoder: Include encoding time in get_min_playback_delay()
This way all the minimum delay calculation is in one place and this
makes gstreamer's implementation closer to the mjpeg one.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-05-16 08:26:18 +01:00
Francois Gouget
a9c5bb974a mjpeg: Remove the unused MJPEG_LOW_FPS_RATE_TH constant
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-05-16 08:23:05 +01:00
Francois Gouget
d09c9b43e0 reds: Enable mm_time adjustments on startup
This reinstates the reds_enable_mm_time() call in do_spice_init()
that was removed by commit c541d7e29d.

We send mm_time adjustments to the client whenever there is no audio
playback. There is no audio playback on startup. Therefore
mm_time_enabled must be true on startup. QED.

This fixes adjusting the client mm_time whenever playing a silent
video (or full desktop stream) when no sound has been played before
such as when using Xspice, booting an OS with no startup or login
jingle, or possibly when migrating a VM (per commit 1c154ea5ec).

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-05-16 08:23:00 +01:00
Frediano Ziglio
07adcce16e dcc: Avoid usage of not aligned GlzEncDictRestoreData structure
Copy to/from unaligned field to avoid potential unaligned access.
Although it adds a copy it's not in a hot path (migration) and
the structure is pretty small.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-05-13 14:15:19 +01:00
Frediano Ziglio
753ebc0e7c test-display-base: Use SPICE_CONTAINEROF to avoid alignment warning
This change prevent a warning issued by GCC 9 and potentially
other compilers.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-05-13 14:13:21 +01:00
Frediano Ziglio
d417a0bdfd Disable recording filtering for Windows
Although this feature can be ported to Windows doing so would
require the usage of g_spawn_async_with_fds, which is only available
in GLib 2.58 or some specific Win32 code.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:33 +01:00
Frediano Ziglio
9a07eb6582 red-stream: Fix SSL connection for Windows
Set correctly errno to make callers handle correctly encrypted
traffic.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:31 +01:00
Frediano Ziglio
fd90a9d084 tests: Exclude tests that cannot work on Windows
test-stream test is passing file descriptor using Unix socket.
test-stat-file needs some porting work of mmap feature.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:28 +01:00
Frediano Ziglio
d0ae7f157d dispatcher: Port to Windows
Replace poll call with select.
As socket is set to non-blocking we must support it so if
we detect an EAGAIN error wait for data.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:26 +01:00
Frediano Ziglio
524acca643 windows: Disable code not working on Windows
- global signals;
- CLOEXEC flag;
- mmap and statistics;
- IPTOS_LOWDELAY flag;
- Unix sockets;
- sharing file descriptors through Unix sockets;
- TCP_CORK flag.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:22 +01:00
Frediano Ziglio
c8ab3c2c98 test-channel: Use socket compatibility layer
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:20 +01:00
Frediano Ziglio
5ab0667eff test-leaks: Use socket compatibility layer
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:18 +01:00
Frediano Ziglio
3a95e77af2 dispatcher: Use socket compatibility layer
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:16 +01:00
Frediano Ziglio
5c65107663 red-stream: Use socket compatibility layer
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:14 +01:00
Frediano Ziglio
14d4cdebc3 reds: Use socket compatibility layer (close -> socket_close)
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:12 +01:00
Frediano Ziglio
026fab1825 net-utils: Port to Windows
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:08 +01:00
Frediano Ziglio
0c59394b24 sys-socket: Add socket_newpair utility
Allows to easier port socketpair.
Windows does not have this function, we need to create a pair
using 2 internet sockets and connecting one to the other.
The SPICE core interface implementation provided by Qemu under
Windows requires, under Windows, to provide SOCKET handles
so pipes or other Windows handles won't work.
Windows does not provide a socketpair function so use this
replacement.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:14:05 +01:00
Frediano Ziglio
55dd7410b0 sys-socket: Introduce some utility to make sockets more portable
Between Unix and Windows socket are quite different:
- on Windows sockets have a different namespace from C file
  descriptors so you can't use read/write/close or similar functions;
- errors are not stored in errno but you must be read/write the
  errors with specific function;
- sometimes sockets are put in non-blocking mode automatically
  calling some functions;
- SOCKET type is 64 bit on Windows 64 which does not fit technically
  in an int. Is however safe to assume them to fit in an int.

So encapsulate the socket APIs in some definition to make easier
and more safe to deal with them.
Where the portability to Windows would make to code more offuscated a Unix
style was preferred. For instance if errors are detected errno is set from
Windows socket error instead of changing all code handling.
Fortunately on Windows Qemu core interface accepts socket (but not
other types like C file descriptors!).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-05-07 10:14:00 +01:00
Frediano Ziglio
8031558ee3 tests: Provide alarm replacement for Windows
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:13:58 +01:00
Frediano Ziglio
50be664da2 windows: Do not use conflicting preprocessor macros
"interface" and "MAX_MONITORS" are defined in some Windows system
headers causing garbage code to be fed to the compiler.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:13:56 +01:00
Frediano Ziglio
992226d6f2 Avoids %m in formatting for Windows
Not supported, %m is a GNU extension of sscanf.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:13:53 +01:00
Frediano Ziglio
0643d67557 build: Detect Windows build and change some definitions
Windows needs some specific setting to use network.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-07 10:13:48 +01:00
Frediano Ziglio
ed68d491fd Do not check for HAVE_CONFIG_H
This should always be defined and including config.h is a requirement.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-04-30 09:26:55 +01:00
Benjamin Tissoires
ff9c8d4908 inputs-channel: Attempt to have a reliable led state
We can not consider the qemu led state to be reliable. It by default has
50ms of delay, so if we want to achieve something reliable, this won't do.

We need to keep our own internal state, and consider it as reliable.
We update it immediately after receiving the key presses, meaning that this
is now the future state of the guest.

When we receive a keymap event, we check against this 'ideal' state and
only update the guest if we 'counted' that it won't have the correct state.

When the guest notifies its change, the modifiers_watch is supposed to
fix any wrong state.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-04-30 09:05:07 +01:00
Francois Gouget
5efc8fc8ad video-stream: use the dcc local variable
In update_client_playback_delay()

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-04-11 09:51:40 +00:00
Frediano Ziglio
20daba6bc3 red-worker: Remove unused definitions
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-29 15:18:49 +00:00
Frediano Ziglio
e8fb0957ef red-worker: Use bool for driver_cap_monitors_config
Easier to understand.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-29 15:18:47 +00:00
Frediano Ziglio
70612bf297 red-channel: Small comment on "core" field
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-29 15:18:35 +00:00
Frediano Ziglio
62bc14d81d display-channel: Inline red_migrate_display function
The only caller only called that function.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 20:20:25 +00:00
Frediano Ziglio
ee5cdb7e2f Move image_compression field from RedWorker to DisplayChannel
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 20:20:25 +00:00
Frediano Ziglio
163b3c39b6 Check image compression value earlier
Do not check it after assigning to reds->config->image_compression,
check the value as soon as possible.
This prevent potential invalid settings.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 20:20:25 +00:00
Frediano Ziglio
bd55e74f64 red-worker: Remove only assigned fields
DisplayChannelClient get them directly from reds (they are changed
only during initialisation so they can be read freely from any
thread).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 20:20:25 +00:00
Jonathon Jongsma
14403117b5 Make channel client callbacks virtual functions
Rather than having an API to register client callbacks for each channel
type, make them vfuncs.

Since the client callbacks are registered identically for each channel
of the same type, it doesn't make sense for to require these to be
registered separately for each object.  It's cleaner to have these be
per-class properties, so they've been converted to virtual functions.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-28 20:20:25 +00:00
Frediano Ziglio
fe52264204 Check running state in red_qxl_set_client_capabilities
No reasons to expose red_qxl_is_running, this was used to not
send capability is the state was not running.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 20:20:25 +00:00
Frediano Ziglio
0399cd2f90 Move DisplayChannel callbacks from RedWorker to DisplayChannel
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 20:20:25 +00:00
Jonathon Jongsma
b0eab081be Save running property in QXLState
This is a preparatory patch that states the running property in QXLState
and provides accessor functions that allows us to check whether the QXL
device is running from different threads.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-28 20:20:25 +00:00
Frediano Ziglio
571dc645c5 Move thread/dispatching handling to RedChannel
Currently channel threading/handling is spread between RedQxl,
RedWorker and RedChannel.
Move more to RedChannel simplify RedQxl and RedWorker.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 20:20:25 +00:00
Frediano Ziglio
46efdc1e09 dispatcher: Allows to manage messages without registering them
The only way to add new message to Dispatcher was to register
using a number. These numbers corresponded to array indexes.
This is good if the list of messages is allocated statically
and contiguously, on the contrary this method is not that
flexible.
Writing a header of 4 or 16 bytes using system call does not
make much difference so pass all message information in the
payload header.
A new dispatcher_send_message_custom function allows to send
a message passing all message information, including the
pointer to the handler.
This will allow for instance a Dispatcher associate to a given
thread to be reused by different classes.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-28 15:38:16 +00:00
谢 昆明
699151e198 Remove a duplicated line
Signed-off-by: kunming.xie <kunming.xie@hotmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-22 10:16:30 +00:00
Francois Gouget
10870a0e0f Consistently check if drm_dma_buf_fd is greater or lower than zero
Based on a patch by Frediano Ziglio.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-21 12:01:25 +00:00
Francois Gouget
7988d2fe12 dcc: Remove a redundant NULL pointer check in dcc_create_surface()
dcc_create_surface() already returns immediately if dcc is NULL.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-21 11:31:41 +00:00
Christophe Fergeau
4f8db6fac3 worker: Fix potential sprintf overflow
If worker->qxl->id is bigger than 0x7ffffff (in other words, it's a
negative signed int) then
printf(worker_str, "display[%d]", worker->qxl->id);
will need:

"display[]" -> 9 bytes
%d -> 11 bytes

The trailing \0 will thus overflow our 20 bytes destination.
As QXLInstance::id should be an unsigned int, this commit changes the
format string to use %u. This also switches to snprintf.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-21 11:14:53 +00:00
Frediano Ziglio
bcf55b978f red-worker: Use mnemonic for statistic buffer
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-21 11:14:30 +00:00
Frediano Ziglio
d071944043 main-dispatcher: Use reds as opaque for dispatcher
No reason to pass through MainDispatcher, the purpose of
MainDispatcher is to call reds functions from the right thread.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-20 20:40:03 +00:00
Frediano Ziglio
fe4662a99a main-dispatcher: Inline main_dispatcher_self_handle_channel_event
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-20 20:40:03 +00:00
Frediano Ziglio
cd899c4fbd dispatcher: Use NULL for pointer check
handler is a pointer, check for NULL, not 0.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-03-20 16:29:23 +00:00
Frediano Ziglio
c213bbe7cf reds: Check we don't register a channel twice in reds_register_channel
To avoid potential regressions, check it only if extra checks are
enabled.
This allows to check previous "Move channel registration to constructed
vfunc" commit.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2019-03-20 10:43:17 +00:00
Frediano Ziglio
52f716e1d2 test-stream-device: Remove interface before next loop
We should not reuse the same interface twice as doing so will
cause dangling pointers.
Unregister it at every iteration.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-19 13:59:04 +00:00
Frediano Ziglio
7f57ff0186 Remove support for 64 bit pointers on protocol
Import "codegen: Remove support for --ptrsize" change from spice-common
and update code accordingly.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-18 12:42:32 +00:00
Douglas Paul
116ff8ca89 video-stream: prevent crash on stream reattach
I experienced some crashes with qemu 3.1.0 compiled with libspice-server
0.14.0 on Gentoo.

The problem reproduced reliably with a guest running Ubuntu 18.04.2 LTS.
If I connect a viewer at system startup, I would get a crash just after
the fade-in of the login prompt in GDM.

Interestingly, I usually was unable to reproduce the issue if I waited
to connect until after the greeter was fully displayed.

The patch I used to correct the issue for me applies to the master
branch cleanly, so I suspect the problem may still exist.

The only other references to this issue I could find were two abrt
reports in CentOS:
https://bugs.centos.org/view.php?id=15171
https://bugs.centos.org/view.php?id=15441

I'm not sure if the agent->video_encoder is supposed to be guaranteed to
exist when this function is called.

Signed-off-by: Douglas Paul <doug@bogon.ca>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-18 10:41:46 +00:00
Jonathon Jongsma
6f90c003e8 Move channel registration to constructed vfunc
For the Display Channel and the Cursor channel, move the call to
reds_register_channel() to the _constructed() vfunc rather than calling
it explicitly from RedWorker. This matches what other channels do.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-15 09:01:28 +00:00
Victor Toso
679b63fe6e display-channel: monitors config debug: add head number
The difference is subtle but compared to what client receives, this
could help identify values set to the wrong head, e.g:

First we received:
 | display-channel.c:180:monitors_config_debug: monitors config count:2 max:4
 | display-channel.c:184:monitors_config_debug: +0+0 1015x805
 | display-channel.c:184:monitors_config_debug: +1015+0 1024x740

And then:
 | display-channel.c:180:monitors_config_debug: monitors config count:3 max:4
 | display-channel.c:184:monitors_config_debug: +0+0 1015x805
 | display-channel.c:184:monitors_config_debug: +0+0 0x0
 | display-channel.c:184:monitors_config_debug: +1015+0 1024x740

In the first debug it would be helpful to have "head 0" and "head 1",
to point out the temporary error in monitor's config message.

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-11 08:53:25 +00:00
Jonathon Jongsma
105e63dd81 Switch some boolean fields to 'bool' type
For coding style consistency, use 'bool' when we want to represent a
boolean value.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-06 18:59:36 +00:00
Jonathon Jongsma
4c8b485ac4 Only send device display info to supported agents
Only send the graphics device display info to agents that advertise the
VD_AGENT_CAP_GRAPHICS_DEVICE_INFO capability

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-06 18:59:34 +00:00
Jonathon Jongsma
6cb0c19daf Refactor agent_adjust_capabilities() function
Make this a RedsState member function rather than a standalone function.
This means that we simply pass RedsState* as an argument rather than the
internal member variables of RedsState. This enables the following
commit which handles the VD_AGENT_CAP_GRAPHICS_DEVICE_INFO capability to
avoid sending graphics device info to agents that do not support it.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-06 18:59:23 +00:00
Frediano Ziglio
89796d2446 test-stat: Adjust delay checks
usleep under Windows does not seem to have the required precision.
Use milliseconds and adjust check times according.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-03-06 11:59:54 +00:00
Frediano Ziglio
98b8c725f2 Use proper format strings for spice_log
Formatting string should be compatible with GLib.
GLib uses formatting types compatible with GNU.
For Linux this is not an issue as both systems (like a printf) and
GLib one uses the same formatting type.  However on Windows they
differs potentially causing issues.
This is also make worse as GLib 2.58 changed format attribute from
__printf__ to gnu_printf (Microsoft compatibility formats like %I64d
are still supported but you'll get warnings using GCC/Clang
compilers).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-03-05 13:55:47 +00:00
Frediano Ziglio
6d8d4d556a red-pipe-item: Removed some not necessary headers inclusions
RedPipeItem is not using the Ring structures anymore.
Also is not using GLib functionality.
Just include base headers.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-02-23 05:12:59 +00:00
Frediano Ziglio
818e44b5df reds: Check QXL ID registering interface
Avoid to register multiple interface with the same ID.
This would result in issues as 2 channels would have the same
(channel_type, channel_id) which must be unique.
Qemu always allocates QXL interface with IDs starting from 0.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-02-14 12:36:58 +00:00
Frediano Ziglio
d15382d9a7 reds: Reuse agent_dev local variable
The field is only assigned in do_spice_init, surely won't change
in the meanwhile.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-02-14 12:36:56 +00:00
Frediano Ziglio
9fec0306f2 reds: Use proper enumeration for read_state field
Allows the compiler to catch some additional errors.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-02-14 12:36:52 +00:00
Eduardo Lima (Etrunko)
afb2ec312b meson: Bump libcacard requirement to 2.5.1
This had already been done for autotools in spice-common commit
924f47a653bd87fbd50229ee34b58d7b9a3f1ec8.

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-02-13 17:00:04 +00:00
Eduardo Lima (Etrunko)
8abeda90f8 meson: Use gnu_symbol_visibility keyword introduced in meson 0.48
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-02-13 17:00:02 +00:00
Frediano Ziglio
a7a8487d0f Remove core parameter from main_dispatcher_new
This was added in bd8771adbc.
There's no reason to not use reds function instead.
MainDispatcher needs to listen in the main thread that is the
one provided by reds_core_* functions.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-02-12 22:34:52 +00:00
Frediano Ziglio
b9e24dba58 test-stream-device: Check monitor ID messages
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-02-12 22:34:40 +00:00
Frediano Ziglio
3838f5470b reds: Factor out a function to marshal VDAgentGraphicsDeviceInfo message
Instead of scanning the monitor twice (one to compute the size
and another to build the message) use a single function to
marshal the message.
This also fixes big endian machines (which are not supported).
Marshal function is exported to make easier to test (see following
patch).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-02-12 21:24:54 +00:00
Frediano Ziglio
ca7fe46a73 agent-msg-filter: Simplify code
Most of the time result is set to AGENT_MSG_FILTER_OK, set at
the beginning and change if necessary.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-02-12 21:02:44 +00:00
Frediano Ziglio
950e60db91 reds: Fix typo in comment
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-02-11 18:07:22 +00:00
Frediano Ziglio
327a677b0d reds: Fix typos in comments
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2019-02-11 15:29:17 +00:00
Frediano Ziglio
0a415abf35 agent-msg-filter: Add some comments to AgentMsgFilter structure
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2019-02-11 15:15:59 +00:00
Frediano Ziglio
fd72b94965 smartcard-channel-client: Update usage of GObject private structures
This finished the work of 90ff154b36
(cfr "Update usage of GObject private structures").
Removes last call to g_type_class_add_private.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2019-02-11 13:07:59 +00:00
Christophe Fergeau
9a605dcc67 smartcard: Improve on_message_from_device readability
This removes a not really useful switch/case, and changes the function
to exit early on error cases, rather than exiting early in the nominal
case.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-02-11 13:07:00 +00:00
Christophe Fergeau
6c79fd31e0 smartcard: Rework smartcard_get_vsc_msg_item a bit
This renames the method to smartcard_new_vsc_msg_item as this creates a
new object. This also removes the creation of a temporary VHeader which
is then going to be duplicated.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-02-11 13:06:58 +00:00
Christophe Fergeau
44836fb55d smartcard: Remove redundant test in smartcard_char_device_on_message_from_device()
The function returns NULL if vheader->type is VSC_Init so no need to
check it a second time.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-02-11 13:06:55 +00:00
Christophe Fergeau
2b7632b376 smartcard: Remove unused smartcard_get_vsc_msg_item argument
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-02-11 13:06:51 +00:00
Christophe Fergeau
dedc4184c9 char-device: Make send_tokens_to_client() optional
Only RedCharDeviceVDIPortClass implements this vfunc, rather than
forcing every classes deriving from RedCharDeviceClass to implement it,
red_char_device_send_tokens_to_client() can deal with it.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-02-08 17:25:46 +01:00
Eduardo Lima (Etrunko)
90ff154b36 Update usage of GObject private structures
New functions and macros have been added in glib 2.38 to better handle
this case.

c8de2b11bb/NEWS

G_TYPE_INSTANCE_GET_PRIVATE will be deprecated in GLib 2.58.

https://gitlab.gnome.org/GNOME/glib/merge_requests/7/commits

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-02-08 11:49:15 +00:00
Christophe Fergeau
474158dfef ssl: Dump OpenSSL error stack on errors
Bugs such as https://bugzilla.redhat.com/show_bug.cgi?id=1651882 can be
quite tricky to figure out without the detailed OpenSSL error. This
commit adds a detailed dump of the OpenSSL error stack when an OpenSSL
failure happens.

In the bug above, this would have displayed:
(process:13154): Spice-WARNING **: 05:43:10.139: reds.c:2816:reds_init_ssl: Could not load certificates from /etc/pki/libvirt-spice/server-cert.pem

(process:13154): Spice-WARNING **: 05:43:10.140: error:140AB18F:SSL routines:SSL_CTX_use_certificate:ee key too small

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-02-07 09:55:11 +00:00
Christophe Fergeau
a4a16ac42d memslot: Fix off-by-one error in group/slot boundary check
RedMemSlotInfo keeps an array of groups, and each group contains an
array of slots. Unfortunately, these checks are off by 1, they check
that the index is greater or equal to the number of elements in the
array, while these arrays are 0 based. The check should only check for
strictly greater than the number of elements.

For the group array, this is not a big issue, as these memslot groups
are created by spice-server users (eg QEMU), and the group ids used to
index that array are also generated by the spice-server user, so it
should not be possible for the guest to set them to arbitrary values.

The slot id is more problematic, as it's calculated from a QXLPHYSICAL
address, and such addresses are usually set by the guest QXL driver, so
the guest can set these to arbitrary values, including malicious values,
which are probably easy to build from the guest PCI configuration.

This patch fixes the arrays bound check, and adds a test case for this.
This fixes CVE-2019-3813.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-02-05 14:05:49 +01:00
Frediano Ziglio
59f0efb5de red-stream-device: Constify stream_device_get_device_display_info result
There should be no reason for the caller to modify the internal
structure.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-02-04 19:44:12 +00:00
Frediano Ziglio
9bf95486e5 event-loop: Port to Windows
Use g_io_channel_win32_new_socket instead of g_io_channel_unix_new

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-01-31 11:06:37 +00:00
Frediano Ziglio
ec71c795f3 replay: Port to Windows
Client process termination did not work for Windows, used Win32
APIs.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-01-31 11:03:19 +00:00
Frediano Ziglio
aed85f0ff1 test-listen: Exclude Unix sockets part under Windows
Windows does not support Unix sockets.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-01-31 10:59:39 +00:00
Frediano Ziglio
b69fe6cb33 reds: Explicitly include inttypes.h
MingW does not include this header while including stdint.h so
on Windows you need to include it.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-01-31 10:49:54 +00:00
Frediano Ziglio
f8e8ac4910 windows: Do not include headers not available on Windows
This is a preparatory patch for next portability patches

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-01-31 10:48:34 +00:00
Frediano Ziglio
e91c57e6f4 red-qxl: Use proper formatting string for size_t
Avoids issues with LLP64 systems.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-01-31 10:35:02 +00:00
Frediano Ziglio
b4825e4b6b display-channel: Remove unused includes
display-channel.h is not using any of the definition from
these headers.
Adding a missing include to red-worker.c.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-01-30 15:44:47 +00:00
Frediano Ziglio
70a724be6e red-stream-device: Fix "make syntax-check"
Avoid using strncpy, considered not secure.
In this case a simple memcpy is used, we are going to terminate
the string in any case on the next line.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Lukáš Hrázký <lhrazky@redhat.com>
2019-01-30 15:18:59 +00:00
Frediano Ziglio
3a58f08ca4 image-encoders: Initialize Zlib lazily
Zlib structure take up more than 1MB and it is rarely used nowadays
as it is not much effective.
Initialise it only when necessary saving some memory in the normal
case.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-01-30 13:07:32 +00:00
Uri Lublin
889e6273bf smartcard: do not keep weak ref when device is NULL
When a client disconnects, smartcard_channel_client_set_char_device
is called with a NULL "device" argument. In that case there is
no need to take a weak reference to the device.

Without this patch the server complains:
  g_object_add_weak_pointer: assertion 'G_IS_OBJECT (object)' failed

and aborts when a second client attempts to connect.

Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-01-30 09:27:52 +00:00
Lukáš Hrázký
c8e949cea1 Send the graphics device info from streaming agent to the vd_agent
Adds the graphics device info from the streaming device(s) to the
VDAgentGraphicsDeviceInfo message sent to the vd_agent.

Signed-off-by: Lukáš Hrázký <lhrazky@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-01-29 15:47:00 +01:00
Lukáš Hrázký
e032e93411 Receive the GraphicsDeviceInfo message from the streaming agent
Receives the GraphicsDeviceInfo message from the streaming agent and
stores the data in a list on the streaming device.

Signed-off-by: Lukáš Hrázký <lhrazky@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-01-29 15:46:54 +01:00
Lukáš Hrázký
852ae0255c Send the graphics device info to the vd_agent
Sends the device address and device display IDs to the vdagent. The
message is sent either in reaction to the SPICE_MSGC_MAIN_AGENT_START
message or when the graphics device info changes.

Signed-off-by: Lukáš Hrázký <lhrazky@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-01-29 15:46:28 +01:00
Lukáš Hrázký
eceab252be QXL interface: improve the spice_qxl_set_device_info documentation
Instead of one unsupported example, present two real world examples.

Signed-off-by: Lukáš Hrázký <lhrazky@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-01-28 19:35:53 +00:00
Lukáš Hrázký
e3a2f9bb01 QXL interface: deprecate spice_qxl_set_max_monitors
Replace it by spice_qxl_set_device_info. Note we can't use
monitors_count for what's stored in max_monitors, because monitors_count
denotes the length of the device_display_ids array, which
spice_qxl_set_max_monitors doesn't touch.

Signed-off-by: Lukáš Hrázký <lhrazky@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-01-26 09:40:10 +00:00
Lukáš Hrázký
3de5f9ff48 QXL interface: add a function to identify monitors in the guest
Adds a function to let QEMU provide information to identify graphics
devices and their monitors in the guest. The function
(spice_qxl_set_device_info) sets the device address (e.g. a PCI path)
and monitor ID -> device display ID mapping of displays exposed by given
QXL interface.

Signed-off-by: Lukáš Hrázký <lhrazky@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-01-26 09:40:10 +00:00
Frediano Ziglio
08659f91b4 red-worker: Remove obsolete type definition
AsyncCommand was removed in eb6c8ba025.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-01-23 21:22:37 +00:00
Frediano Ziglio
e5bc6f952c Trace streaming device data using recorder
Trace when data is received from the guest and when is sent
to the client.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-01-23 14:51:01 +00:00
Frediano Ziglio
c67876757f Reuse SPICE_UPCAST instead of SPICE_CONTAINEROF where possible
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-01-17 16:34:23 +00:00
Christophe Fergeau
9b04c9961e sasl: Simplify red_stream_write_u32_le call with '0' serveroutlen
Instead of
if (serveroutlen) {
...
} else {
    red_stream_write_u32_le(stream, serveroutlen);
}

use 'red_stream_write_u32_le(stream, 0);' in the else block as it's
slightly more obvious.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-01-15 17:07:44 +01:00
Frediano Ziglio
6a463dc129 red-replay-qxl: Use PRIxPTR constant for string formatting
These constants are meant to be used in format string for pointers
types. Use them for portability.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-01-08 12:48:53 +00:00
Frediano Ziglio
c55058563f test-display-base: Remove error from "make syntax-check"
Due to previous commit "make syntax-check" command reports:

prohibit_signal_without_use
server/tests/test-display-base.c
maint.mk: the above files include signal.h but don't use it
make: *** [maint.mk:639: sc_prohibit_signal_without_use] Error 1

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-01-03 15:10:19 +00:00
Frediano Ziglio
5cbdf1a235 test-display-base: Port to Windows
Use GLib function to launch and wait process exit.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-01-03 13:08:17 +00:00