[Spice-devel] [PATCH spice-gtk 8/8] Do not send specific messages in read-only
Hans de Goede
hdegoede at redhat.com
Wed Nov 23 06:40:25 PST 2011
Ack.
On 11/23/2011 01:23 PM, Marc-André Lureau wrote:
> ---
> gtk/channel-inputs.c | 22 +++++++++++++++++++++-
> gtk/channel-main.c | 5 ++++-
> gtk/channel-record.c | 5 +++++
> gtk/channel-smartcard.c | 3 +++
> gtk/channel-usbredir.c | 3 +++
> gtk/spice-channel-priv.h | 1 +
> gtk/spice-channel.c | 8 +++++++-
> 7 files changed, 44 insertions(+), 3 deletions(-)
>
> diff --git a/gtk/channel-inputs.c b/gtk/channel-inputs.c
> index f6c4a3e..bacbba3 100644
> --- a/gtk/channel-inputs.c
> +++ b/gtk/channel-inputs.c
> @@ -215,6 +215,9 @@ static void send_position(SpiceInputsChannel *channel)
> {
> SpiceMsgOut *msg;
>
> + if (spice_channel_get_read_only(SPICE_CHANNEL(channel)))
> + return;
> +
> msg = mouse_position(channel);
> if (!msg) /* if no motion */
> return;
> @@ -228,6 +231,9 @@ static void send_motion(SpiceInputsChannel *channel)
> {
> SpiceMsgOut *msg;
>
> + if (spice_channel_get_read_only(SPICE_CHANNEL(channel)))
> + return;
> +
> msg = mouse_motion(channel);
> if (!msg) /* if no motion */
> return;
> @@ -382,6 +388,8 @@ void spice_inputs_button_press(SpiceInputsChannel *channel, gint button,
>
> if (SPICE_CHANNEL(channel)->priv->state != SPICE_CHANNEL_STATE_READY)
> return;
> + if (spice_channel_get_read_only(SPICE_CHANNEL(channel)))
> + return;
>
> c = channel->priv;
> switch (button) {
> @@ -428,6 +436,8 @@ void spice_inputs_button_release(SpiceInputsChannel *channel, gint button,
>
> if (SPICE_CHANNEL(channel)->priv->state != SPICE_CHANNEL_STATE_READY)
> return;
> + if (spice_channel_get_read_only(SPICE_CHANNEL(channel)))
> + return;
>
> c = channel->priv;
> switch (button) {
> @@ -442,7 +452,7 @@ void spice_inputs_button_release(SpiceInputsChannel *channel, gint button,
> break;
> }
>
> - c->bs = button_state;
> + c->bs = button_state;
> send_motion(channel);
> send_position(channel);
>
> @@ -471,6 +481,8 @@ void spice_inputs_key_press(SpiceInputsChannel *channel, guint scancode)
> g_return_if_fail(SPICE_CHANNEL(channel)->priv->state != SPICE_CHANNEL_STATE_UNCONNECTED);
> if (SPICE_CHANNEL(channel)->priv->state != SPICE_CHANNEL_STATE_READY)
> return;
> + if (spice_channel_get_read_only(SPICE_CHANNEL(channel)))
> + return;
>
> SPICE_DEBUG("%s: scancode %d", __FUNCTION__, scancode);
> if (scancode< 0x100) {
> @@ -502,6 +514,8 @@ void spice_inputs_key_release(SpiceInputsChannel *channel, guint scancode)
> g_return_if_fail(SPICE_CHANNEL(channel)->priv->state != SPICE_CHANNEL_STATE_UNCONNECTED);
> if (SPICE_CHANNEL(channel)->priv->state != SPICE_CHANNEL_STATE_READY)
> return;
> + if (spice_channel_get_read_only(SPICE_CHANNEL(channel)))
> + return;
>
> SPICE_DEBUG("%s: scancode %d", __FUNCTION__, scancode);
> if (scancode< 0x100) {
> @@ -552,6 +566,9 @@ void spice_inputs_set_key_locks(SpiceInputsChannel *channel, guint locks)
> {
> SpiceMsgOut *msg;
>
> + if (spice_channel_get_read_only(SPICE_CHANNEL(channel)))
> + return;
> +
> msg = set_key_locks(channel, locks);
> if (!msg) /* you can set_key_locks() even if the channel is not ready */
> return;
> @@ -566,6 +583,9 @@ static void spice_inputs_channel_up(SpiceChannel *channel)
> SpiceInputsChannelPrivate *c = SPICE_INPUTS_CHANNEL(channel)->priv;
> SpiceMsgOut *msg;
>
> + if (spice_channel_get_read_only(channel))
> + return;
> +
> msg = set_key_locks(SPICE_INPUTS_CHANNEL(channel), c->locks);
> spice_msg_out_send_internal(msg);
> spice_msg_out_unref(msg);
> diff --git a/gtk/channel-main.c b/gtk/channel-main.c
> index 90eb0fd..b2d44b6 100644
> --- a/gtk/channel-main.c
> +++ b/gtk/channel-main.c
> @@ -1054,11 +1054,14 @@ static void set_mouse_mode(SpiceMainChannel *channel, uint32_t supported, uint32
> }
>
> /* switch to client mode if possible */
> - if ((supported& SPICE_MOUSE_MODE_CLIENT)&& (current != SPICE_MOUSE_MODE_CLIENT)) {
> + if (!spice_channel_get_read_only(SPICE_CHANNEL(channel))&&
> + supported& SPICE_MOUSE_MODE_CLIENT&&
> + current != SPICE_MOUSE_MODE_CLIENT) {
> SpiceMsgcMainMouseModeRequest req = {
> .mode = SPICE_MOUSE_MODE_CLIENT,
> };
> SpiceMsgOut *out;
> +
> out = spice_msg_out_new(SPICE_CHANNEL(channel), SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST);
> out->marshallers->msgc_main_mouse_mode_request(out->marshaller,&req);
> spice_msg_out_send_internal(out);
> diff --git a/gtk/channel-record.c b/gtk/channel-record.c
> index 443337c..bb66c3b 100644
> --- a/gtk/channel-record.c
> +++ b/gtk/channel-record.c
> @@ -277,6 +277,8 @@ static void spice_record_mode(SpiceRecordChannel *channel, uint32_t time,
> SpiceMsgOut *msg;
>
> g_return_if_fail(channel != NULL);
> + if (spice_channel_get_read_only(SPICE_CHANNEL(channel)))
> + return;
>
> m.mode = mode;
> m.time = time;
> @@ -309,6 +311,8 @@ static void spice_record_start_mark(SpiceRecordChannel *channel, uint32_t time)
> SpiceMsgOut *msg;
>
> g_return_if_fail(channel != NULL);
> + if (spice_channel_get_read_only(SPICE_CHANNEL(channel)))
> + return;
>
> m.time = time;
>
> @@ -336,6 +340,7 @@ void spice_record_send_data(SpiceRecordChannel *channel, gpointer data,
> uint8_t *celt_buf = NULL;
>
> g_return_if_fail(channel != NULL);
> + g_return_if_fail(spice_channel_get_read_only(SPICE_CHANNEL(channel)) == FALSE);
>
> rc = channel->priv;
>
> diff --git a/gtk/channel-smartcard.c b/gtk/channel-smartcard.c
> index 5fec217..c5aa17b 100644
> --- a/gtk/channel-smartcard.c
> +++ b/gtk/channel-smartcard.c
> @@ -281,6 +281,9 @@ static void smartcard_message_send(SpiceSmartcardChannel *channel,
> {
> SpiceSmartcardChannelMessage *message;
>
> + if (spice_channel_get_read_only(SPICE_CHANNEL(channel)))
> + return;
> +
> SPICE_DEBUG("smartcard: send message %d, %s",
> msg_type, queue ? "queued" : "now");
> if (!queue) {
> diff --git a/gtk/channel-usbredir.c b/gtk/channel-usbredir.c
> index c0991c9..e1d2f86 100644
> --- a/gtk/channel-usbredir.c
> +++ b/gtk/channel-usbredir.c
> @@ -191,6 +191,9 @@ void spice_usbredir_channel_do_write(SpiceUsbredirChannel *channel)
> {
> SpiceUsbredirChannelPrivate *priv = channel->priv;
>
> + if (spice_channel_get_read_only(SPICE_CHANNEL(channel)))
> + return;
> +
> /* No recursion allowed! */
> g_return_if_fail(priv->msg_out == NULL);
>
> diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h
> index df661f8..83e7e25 100644
> --- a/gtk/spice-channel-priv.h
> +++ b/gtk/spice-channel-priv.h
> @@ -167,6 +167,7 @@ gint spice_channel_get_channel_id(SpiceChannel *channel);
> gint spice_channel_get_channel_type(SpiceChannel *channel);
> void spice_channel_swap(SpiceChannel *channel, SpiceChannel *swap);
> void spice_channel_set_common_capability(SpiceChannel *channel, guint32 cap);
> +gboolean spice_channel_get_read_only(SpiceChannel *channel);
>
> /* coroutine context */
> #define emit_main_context(object, event, args...) \
> diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
> index c2133ab..c9af0ba 100644
> --- a/gtk/spice-channel.c
> +++ b/gtk/spice-channel.c
> @@ -1561,6 +1561,12 @@ void spice_channel_wakeup(SpiceChannel *channel)
> g_io_wakeup(&c->wait);
> }
>
> +G_GNUC_INTERNAL
> +gboolean spice_channel_get_read_only(SpiceChannel *channel)
> +{
> + return spice_session_get_read_only(channel->priv->session);
> +}
> +
> /* coroutine context if @buffered is FALSE,
> system context if @buffered is TRUE */
> static void spice_channel_send_msg(SpiceChannel *channel, SpiceMsgOut *out, gboolean buffered)
> @@ -1573,7 +1579,7 @@ static void spice_channel_send_msg(SpiceChannel *channel, SpiceMsgOut *out, gboo
> g_return_if_fail(out != NULL);
>
> if (out->ro_check&&
> - spice_session_get_read_only(channel->priv->session)) {
> + spice_channel_get_read_only(channel)) {
> g_warning("Try to send message while read-only. Please report a bug.");
> return;
> }
More information about the Spice-devel
mailing list