Ensure '\0' is not part of text clipboard data

On Windows, with some versions of gtk+, GtkSelectionData::length
will include the final '\0'.
When a string with this trailing '\0' is pasted in some linux
applications, it will be pasted as <NIL> or as an invisible character,
which is unwanted.

This commit ensures the length we send to the agent does not
include any trailing '\0'.

https://bugzilla.redhat.com/show_bug.cgi?id=1090122
channel-display: Remove #ifdef SW_CANVAS_CACHE

It's unconditionnally defined at build time in the global CPP flags, so
the #ifdef SW_CANVAS_CACHE are always enabled and can be removed.
Fix build with automake 1.14

When building a source file from a different directory, automake 1.14
is warning that the automake option 'subdir-objects' must be used:

automake: warnings are treated as errors
gtk/Makefile.am:218: warning: source file
'$(top_srcdir)/spice-common/common/sw_canvas.c' is in a subdirectory,
gtk/Makefile.am:218: but option 'subdir-objects' is disabled
automake: warning: possible forward-incompatibility.
automake: At least a source file is in a subdirectory, but the
'subdir-objects'
automake: automake option hasn't been enabled.  For now, the
corresponding output
automake: object file(s) will be placed in the top-level directory.
However,
automake: this behaviour will change in future Automake versions: they
will
automake: unconditionally cause object files to be placed in the same
subdirectory
automake: of the corresponding sources.
automake: You are advised to start using 'subdir-objects' option
throughout your
automake: project, to avoid future incompatibilities.
autoreconf: automake failed with exit status: 1

This causes the build to fail because we are also using the -Werror
automake option.
Updating the spice-common submodule to git master fixes part of this
issue as 7ea1cc5 'Fix generation of marshallers in VPATH builds' removed
directory references from some source files.

This commit removes the references to
$(top_srcdir)/spice-common/common/sw_canvas.[ch] from gtk/Makefile.am.
At this point, automake subdir-objects support does not seem to cope
very well with source files which are not in relative subdirectories,
see http://mytestbed.net/issues/1327
What is done instead is to add some local client_sw_canvas.[ch] files
which will include the needed files from spice-common with the
appropriate #define set (these sw_canvas.[ch] files are meant to be used
as templates).

This fixes https://bugs.freedesktop.org/show_bug.cgi?id=67304
Fix 'loose' typo
keyboard: wrong defined macro for WIN32

On windows client, there's no effect for guest when
enabling CAPS_LOCK/NUM_LOCK/SCROLL_LOCK on
(because of the delay, guest may take the effect for several seconds).
There's a wrong defined macro, then <modifiers> is ALWAYS 0,
and the keyboard state of guest is synchronized with the state client
by spice_gtk_session_sync_keyboard_modifiers_for_channel(...).
Use G_OS_WIN32 #define everywhere

Currently some parts of the windows specific code is checking for the
WIN32 define, and other parts are checking G_OS_WIN32. This commit uses
G_OS_WIN32 everywhere for consistency.
win32: fix coroutine assertion when switching to TLS port

Since v0.21-35-gbaa51c5, there are some new coroutine preconditions.

The winfiber implementation can reach, when the structure isn't cleared,
which happens when switching channel connection to TLS port and the
coroutine is recycled.

CRITICAL **: coroutine_yieldto: assertion '!to->exited' failed

In a near future, it would be nice to use the safer implementation
proposed for glib, see bgo#719362 (using a private copy)
Wait to send monitor config until agent caps are received

When the first display is disabled and the vdagent is restarted in the guest,
it sometimes becomes enabled. This appears to be caused by a race condition
when an agent becomes connected. When the agent becomes connected, virt-viewer
triggers a display update (spice_main_send_monitor_config()). This display
update happens in a timeout handler, but the timeout interval is set to 0 (so
it behaves basically like an idle handler).

The race happens because spice_main_send_monitor_config() behaves slightly
differently depending on the agent's capabilities. And sometimes the idle
handler runs before the client and server have negotiated capabilities. In this
case, we have to assume that the server does not support sparse monitor
configurations. So instead of sending down an update where display #0 is off
and display #1 is WxH, we send down an update that only a single display:
display #0 is WxH. This results in the first display becoming enabled.

To solve the issue, we wait until the agent negotiates capabilities
before sending the display configuration message.

Resolves: rhbz#1043782, rhbz#1032923
xfer: send data message of size 0 for 0-size file

Make sure we send a xfer data message for 0-size files.
This avoid leaking file descriptiors in guest agent when
copying such files.

Reported-by: Cody Chan <int64ago@gmail.com>

https://bugzilla.redhat.com/show_bug.cgi?id=1135099
win-usb: Initialize GError before using it

GError variables must be set to NULL before passing them to a function
which might set them.
This fixes the runtime warning reported in rhbz#1138195:

(remote-viewer.exe:3896): GLib-WARNING **: GError set over the top of a
previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL
before it's set.
The overwriting error message was: handle_dev_change: Error getting
device list from libusb: Other error [-99]
channel-main: allow transferring multiple files at once

Allow to drag and drop, from host to guest, more than one file at the
same time.
Fix -Wsign-compare
Don't report IO error on clean guest shutdown

Since commit 9cf9ca434, spice_channel_iterate() will report a
SPICE_CHANNEL_ERROR_IO error to library users when
SpiceChannel::has_error is set. In particular, when the server side
closes its SPICE sockets because the VM is being shut down, an IO error
will get reported. Prior to this change, a channel-closed event was
reported on graceful VM shutdowns as there was
a g_socket_condition_check() guarding the emission of the IO error
signal.

This commit readds the g_socket_condition_check() test, but only when
SpiceChannel::has_error is set.

This fixes https://bugs.freedesktop.org/show_bug.cgi?id=83692