Commit Graph

57 Commits

Author SHA1 Message Date
Rosen Penev
fc9ca6c71a clang-tidy: do not use else after return
Found with readability-else-after-return

Easier to read.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-04-11 07:49:21 +01:00
Rosen Penev
944dc8662e clang-tidy: use auto
Found with modernize-use-auto

auto is shorter and can sometimes disambiguate pointer constness.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-04-11 07:44:42 +01:00
Rosen Penev
68b0f3029d clang-tidy: use const reference for loop
Found with performance-for-range-copy

Avoids unnecessary copying when the loop does not modify the variable.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-09 08:21:19 +01:00
Rosen Penev
f64e61e44d clang-tidy: use override and remove virtual
Found with modernize-use-override

This can be useful as compilers can generate a compile time error when:
	The base class implementation function signature changes.
        The user has not created the override with the correct
	signature.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-09 08:20:06 +01:00
Rosen Penev
76f4dc436a clang-tidy: add explicit to single argument constructors
Found with google-explicit-constructor

Explicit prevents type conversions for safety reasons.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-04-08 16:21:10 +01:00
Rosen Penev
11374b28b4 clang-tidy: remove pointless void
Found with modernize-redundant-void-arg

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-04-08 16:18:17 +01:00
Rosen Penev
9f1514b804 clang-tidy: use using
Found with modernize-use-using

Also manually removed a bunch of typedefs as they are no longer useful
in C++.

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rt-using

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-04-08 16:18:02 +01:00
Marc-André Lureau
c23cbd6fa8 reds: start QXL devices if VM is running
Like char devices, QXL devices need to be explicily started.

For some historical reason, char devices are started when in running
state. See commi bf1d9007b. Reading that commit comments, there was a
plan to provide an API to stop/start devices invidually, but that never
happened. Whether that API would really be useful now, I wonder.

For now, just follow the char devices behaviour and start QXL devices
added when vm_running.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.uuuuucom>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-01-29 10:03:24 +00:00
Julien Ropé
ca5bbc5692 With OpenSSL 1.1: Disable client-initiated renegotiation.
Fixes issue #49
Fixes BZ#1904459

Signed-off-by: Julien Ropé <jrope@redhat.com>
Reported-by: BlackKD
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-12-07 14:43:24 +00:00
Frediano Ziglio
de5c20531e reds: Check VDAgentMonitorsConfig using spice-common code
Reduce code duplication.
Also this improve support for big endian machines as
agent_check_message fix also message endianess.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <ulublin@redhat.com>
2020-10-25 20:02:16 +00:00
Frediano Ziglio
587c04f79e Improve big endian support for agent messages
Big endian machines on server are not officially supported but won't
hurt.
Messages from client are always encoded as little endian (as all
SPICE protocol).
Convert fields from little endian to host endian on some places
where numbers are used and not just binary copied.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <ulublin@redhat.com>
2020-10-25 20:01:54 +00:00
Marc-André Lureau
d1bea58002 reds: fix vdagent monitor flag filtering
Fixes commit 828c881bd0a8d73a5c2038bdf22cb8ae7c793482 ("agent/qxl: add
monitors physical dimensions handling").

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-09-17 06:43:48 +01:00
Frediano Ziglio
f1e89573b6 reds: Specify virtual functions override RedCharDevice functions
Remove some possible warning, like

reds.cpp:216:18: warning: 'remove_client' overrides a member function but is not marked 'override' [clang-diagnostic-inconsistent-missing-override]
    virtual void remove_client(RedCharDeviceClientOpaque *opaque);
                 ^

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <ulublin@redhat.com>
2020-09-16 14:34:17 +01:00
Marc-André Lureau
828c881bd0 agent/qxl: add monitors physical dimensions handling
Requires
https://gitlab.freedesktop.org/spice/spice-protocol/-/merge_requests/24

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-09-14 14:35:12 +01:00
Frediano Ziglio
5223aeed32 reds: Use g_strlcpy instead of strlen/strcpy
Some compiler could generate some warning, like

reds.cpp:2678:5: warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
    strcpy(buf, pass);
    ^

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Jakub Janků <jjanku@redhat.com>
2020-09-13 19:47:20 +01:00
Frediano Ziglio
dd9b78fd78 Use smart pointers for RedPipeItem
Reduces usage of manual reference counting.
Avoids usage of new and use instead red::make_shared to both
create and own pipe items.
Use move semantic to reduce useless copies.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-07-13 19:48:08 +01:00
Frediano Ziglio
fa404f73d8 main-channel-client: Pass directly a RedPipeItem from VDI
Provides a base class to allows RedCharDeviceVDIPort to pass
a RedPipeItem to MainChannelClient instead of having to wrap
into another item.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-07-13 19:47:58 +01:00
Frediano Ziglio
d55c8837f8 red-pipe-item: Add and use a small utility class for easier initialization
Most of the times each class has an associated constant so
allows to be able to define the constant at declaration time.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-07-13 19:47:55 +01:00
Frediano Ziglio
a30df693cf red-pipe-item: Use inheritance on RedPipeItem
This allows to:
- reuse reference counting;
- avoid having to manually call g_free to release item memory;
- assure item is initialized;
- avoids some manual casts.

It will also allows to use smart pointers.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-07-13 19:47:53 +01:00
Frediano Ziglio
24c8692e5f Remove useless "common/ring.h" include
Not used directly by these source files.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2020-06-29 08:56:36 +01:00
Frediano Ziglio
0acf650afa reds: Remove not used preprocessor macros
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2020-06-27 06:29:53 +01:00
Frediano Ziglio
4a34111711 reds: Avoid a "end" label just to free password
"password" is pretty small, allocate on stack directly.
RSA is currently 1024 bits, that is more or less 128 bytes.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Kevin Pouget <kpouget@redhat.com>
2020-06-26 10:06:40 +01:00
Frediano Ziglio
69640d1054 reds: Remove useless label and goto statements
Not needed anymore.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Francesco Giudici <fgiudici@redhat.com>
2020-06-25 16:09:25 +01:00
Frediano Ziglio
a10e496c46 char-device: Remove "sin" parameter from read_one_msg_from_device
Not much used, can be retrieved from the class if needed.

There are some apparent test removal on reds.cpp.
The test "if (!reds->vdagent)" apparently disappeared but it's included in
the while.
reds->agent_dev cannot be NULL as SPICE server allows only one agent and we
are into a member of an object so it must be reds->agent_dev.get() == this.
As there's only an agent and as the interface (sin) is extracted from that
agent it must be reds->agent_dev.get() == sin->st and either reds->vdagent
== sin or reds->vdagent == NULL.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-06-23 12:49:43 +01:00
Frediano Ziglio
479a1a74a2 Reuse RedCharDevice::read
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-06-23 12:49:41 +01:00
Frediano Ziglio
8875e79c7c reds: Use socket_close instead of close
socket_close is mapped to close under Unix but under Windows
you should call closesocket instead so call socket_close which
will map to the proper close function on both environments.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <ulublin@redhat.com>
2020-06-18 16:57:50 +01:00
Frediano Ziglio
f03d094942 reds: Remove usage of "this"
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@redhat.com>
2020-06-08 10:00:43 +01:00
Frediano Ziglio
ee4cf6a07c Fix compatibility with MSG_NOSIGNAL and Darwin
Darwin does not have MSG_NOSIGNAL but allows to set a SO_NOSIGPIPE
option to disable sending SIGPIPE writing to closed socket.
Note that *BSD has the SO_NOSIGPIPE option but does not affect all
write calls so instead continue to use MSG_NOSIGNAL instead on
that systems.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-19 10:01:47 +01:00
Frediano Ziglio
fd06625ba1 red-stream-device: Better encapsulation
Remove all members public, set correct access and create
missing methods.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
1e9205a3b8 char-device: Remove GObject from RedCharDevice
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
f6f998004b Wrap spice.h in order to do some adjustment
Instead of including spice.h directly include an header that wraps
it. This allows to remove the SPICE_SERVER_INTERNAL define.
Currently is used to rename SpiceCharDeviceInstance to RedCharDevice
and reduce its visibility to hidden. This remove some warnings
and some weird code in the source.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
2b9e1dcd55 dispatcher: Reuse base reference counting for Dispatcher hierararchy
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
597461e443 Add and use red::make_shared
Allow to create an object already contained in a shared pointer
to avoid having not owned objects.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
5126e38367 Use shared_ptr implementation to handle reference counting
This allows to make easier the management of owning.
Reference counting is automatically updated based on shared
pointers modification.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
b28db35af5 reds: Make mig_wait_disconnect_clients a std::forward_list
In the meanwhile remove a leak on the program.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
9dcf937767 reds: Move qxl_instances to red::safe_list
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
1411383483 char-device: Automatically convert functions to methods
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
5f7aaf2a9a char-device: Remove define trick, won't work on C++
C++ check parameter type, not founding the functions at
link time.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
4233df686e reds: Move clients to safe_list
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
ec66702526 reds: Use red::safe_list instead of GList
Use an utility list.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
ab7486a9e8 main-channel-client: Automatically convert
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
9fd105e925 main-channel: Automatic convert functions to methods
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
cc86a7fb53 red-client: Automatically convert functions to methods
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
43c6bf91b7 reds: Remove a weak pointer usage
RedCharDevice can all be removed just calling unref, beside
the agent that needs special threatment.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
f4aefa728e Remove GObject from Dispatcher hierarchy
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
164a333f99 Define and use (un)ref
Avoids g_object_(un)ref.
This in preparation to remove GObject.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
ea0d056bb7 char-device: Define and use (un)ref
Prepare to remove GObject.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
2d865a78da red-channel-client: Make start_connectivity_monitoring protected
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
9df07e3f20 inputs-channel: Make InputsChannel more encapsulated
Put functions into methods.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00
Frediano Ziglio
104aa6e1af Remove GObject from RedChannel
The patch seems pretty huge but mainly are mechanical steps:
- remove GObject declarations
- do not inherit from GObject
- add SPICE_CXX_GLIB_ALLOCATOR to avoid using C++ allocators
- CLASS_init and CLASS_constructor code goes into C++ constructor
- CLASS_dispose and CLASS_finalize code goes into C++ destructor
- g_object_new is replaced by new operator
- class members goes into virtual methods
- class parameters became argument to constructor
- use push-visibility.h and pop-visibility.h to limit visibility
- temporary use XXX_CAST for old GObject casts, they will
  be replaced
- g_object_get is replaced by accessors

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-05-01 06:58:09 +01:00