From fe4d5599a9aec8bcd2ad53d8e124630a53cd8394 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Wed, 9 Jan 2019 14:01:26 +0100 Subject: [PATCH] conn: Use vnc_connection_has_error() extensively It's better to call this helper rather than directly checking for priv->coroutine_stop. Signed-off-by: Christophe Fergeau (cherry picked from commit ad6478a1e522f5e0c2f396ac3600dc35df5871a8) Resolves: rhbz#1688275 --- src/vncconnection.c | 77 ++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/src/vncconnection.c b/src/vncconnection.c index fd7468b..bbf4373 100644 --- a/src/vncconnection.c +++ b/src/vncconnection.c @@ -736,7 +736,7 @@ static int vnc_connection_read_wire(VncConnection *conn, void *data, size_t len) reread: - if (priv->coroutine_stop) return -EINVAL; + if (vnc_connection_has_error(conn)) return -EINVAL; if (priv->tls_session) { ret = gnutls_read(priv->tls_session, data, len); @@ -885,7 +885,7 @@ static int vnc_connection_read(VncConnection *conn, void *data, size_t len) char *ptr = data; size_t offset = 0; - if (priv->coroutine_stop) return -EINVAL; + if (vnc_connection_has_error(conn)) return -EINVAL; while (offset < len) { size_t tmp; @@ -941,7 +941,7 @@ static void vnc_connection_flush_wire(VncConnection *conn, int ret; gboolean blocking = FALSE; - if (priv->coroutine_stop) return; + if (vnc_connection_has_error(conn)) return; if (priv->tls_session) { ret = gnutls_write(priv->tls_session, @@ -2878,10 +2878,9 @@ static void vnc_connection_tight_update(VncConnection *conn, static void vnc_connection_update(VncConnection *conn, int x, int y, int width, int height) { - VncConnectionPrivate *priv = conn->priv; struct signal_data sigdata; - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return; VNC_DEBUG("Notify update area (%dx%d) at location %d,%d", width, height, x, y); @@ -2896,10 +2895,9 @@ static void vnc_connection_update(VncConnection *conn, int x, int y, int width, static void vnc_connection_bell(VncConnection *conn) { - VncConnectionPrivate *priv = conn->priv; struct signal_data sigdata; - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return; VNC_DEBUG("Server beep"); @@ -2911,11 +2909,10 @@ static void vnc_connection_server_cut_text(VncConnection *conn, const void *data, size_t len) { - VncConnectionPrivate *priv = conn->priv; struct signal_data sigdata; GString *text; - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return; text = g_string_new_len ((const gchar *)data, len); @@ -2933,7 +2930,7 @@ static void vnc_connection_resize(VncConnection *conn, int width, int height) VNC_DEBUG("Desktop resize w=%d h=%d", width, height); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return; priv->width = width; @@ -2949,7 +2946,7 @@ static void vnc_connection_pixel_format(VncConnection *conn) VncConnectionPrivate *priv = conn->priv; struct signal_data sigdata; - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return; sigdata.params.pixelFormat = &priv->fmt; @@ -2967,7 +2964,7 @@ static void vnc_connection_pointer_type_change(VncConnection *conn, gboolean abs return; priv->absPointer = absPointer; - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return; sigdata.params.absPointer = absPointer; @@ -3028,7 +3025,7 @@ static void vnc_connection_rich_cursor(VncConnection *conn, guint16 x, guint16 y priv->cursor = vnc_cursor_new(pixbuf, x, y, width, height); } - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return; sigdata.params.cursor = priv->cursor; @@ -3093,7 +3090,7 @@ static void vnc_connection_xcursor(VncConnection *conn, guint16 x, guint16 y, gu priv->cursor = vnc_cursor_new(pixbuf, x, y, width, height); } - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return; sigdata.params.cursor = priv->cursor; @@ -3405,7 +3402,7 @@ static gboolean vnc_connection_server_message(VncConnection *conn) n_type = vnc_connection_read_u8(conn); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) break; switch (n_type) { @@ -3423,7 +3420,7 @@ static gboolean vnc_connection_server_message(VncConnection *conn) n_length, 1024 * 1024); break; } - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) break; if (!priv->audio) { @@ -3491,7 +3488,7 @@ static gboolean vnc_connection_has_credentials(gpointer data) VncConnection *conn = data; VncConnectionPrivate *priv = conn->priv; - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return TRUE; if (priv->want_cred_username && !priv->cred_username) return FALSE; @@ -3508,7 +3505,7 @@ static gboolean vnc_connection_gather_credentials(VncConnection *conn) VNC_DEBUG("Checking if credentials are needed"); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return FALSE; if (!vnc_connection_has_credentials(conn)) { @@ -3546,7 +3543,7 @@ static gboolean vnc_connection_gather_credentials(VncConnection *conn) g_value_array_free(authCred); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return FALSE; VNC_DEBUG("Waiting for missing credentials"); g_condition_wait(vnc_connection_has_credentials, conn); @@ -3579,13 +3576,13 @@ static gboolean vnc_connection_check_auth_result(VncConnection *conn) vnc_connection_read(conn, reason, len); reason[len] = '\0'; VNC_DEBUG("Fail %s", reason); - if (!priv->coroutine_stop) { + if (!vnc_connection_has_error(conn)) { vnc_connection_set_error(conn, "%s", reason); vnc_connection_auth_failure(conn, reason); } } else { VNC_DEBUG("Fail auth no result"); - if (!priv->coroutine_stop) { + if (!vnc_connection_has_error(conn)) { vnc_connection_set_error(conn, "%s", "Unknown authentication failure"); vnc_connection_auth_failure(conn, "Unknown authentication failure"); } @@ -4197,7 +4194,7 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn) /* Get the supported mechanisms from the server */ mechlistlen = vnc_connection_read_u32(conn); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) goto error; if (mechlistlen > SASL_MAX_MECHLIST_LEN) { vnc_connection_set_error(conn, @@ -4209,7 +4206,7 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn) mechlist = g_malloc(mechlistlen+1); vnc_connection_read(conn, mechlist, mechlistlen); mechlist[mechlistlen] = '\0'; - if (priv->coroutine_stop) { + if (vnc_connection_has_error(conn)) { g_free(mechlist); mechlist = NULL; goto error; @@ -4266,14 +4263,14 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn) vnc_connection_write_u32(conn, 0); } vnc_connection_flush(conn); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) goto error; VNC_DEBUG("%s", "Getting sever start negotiation reply"); /* Read the 'START' message reply from server */ serverinlen = vnc_connection_read_u32(conn); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) goto error; if (serverinlen > SASL_MAX_DATA_LEN) { vnc_connection_set_error(conn, @@ -4292,7 +4289,7 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn) serverin = NULL; } complete = vnc_connection_read_u8(conn); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) goto error; VNC_DEBUG("Client start result complete: %d. Data %u bytes %p '%s'", @@ -4354,13 +4351,13 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn) vnc_connection_write_u32(conn, 0); } vnc_connection_flush(conn); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) goto error; VNC_DEBUG("Server step with %u bytes %p", clientoutlen, clientout); serverinlen = vnc_connection_read_u32(conn); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) goto error; if (serverinlen > SASL_MAX_DATA_LEN) { vnc_connection_set_error(conn, @@ -4379,7 +4376,7 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn) serverin = NULL; } complete = vnc_connection_read_u8(conn); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) goto error; VNC_DEBUG("Client step result complete: %d. Data %u bytes %p '%s'", @@ -4524,7 +4521,7 @@ static gboolean vnc_connection_has_auth_subtype(gpointer data) VncConnection *conn = data; VncConnectionPrivate *priv = conn->priv; - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return TRUE; if (priv->auth_subtype == VNC_CONNECTION_AUTH_INVALID) return FALSE; @@ -4597,15 +4594,15 @@ static gboolean vnc_connection_perform_auth_tls(VncConnection *conn) VNC_DEBUG("Possible TLS sub-auth %u", auth[i]); } - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return FALSE; vnc_connection_choose_auth(conn, VNC_AUTH_CHOOSE_SUBTYPE, nauth, auth); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return FALSE; VNC_DEBUG("Waiting for TLS auth subtype"); g_condition_wait(vnc_connection_has_auth_subtype, conn); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return FALSE; VNC_DEBUG("Choose auth %u", priv->auth_subtype); @@ -4672,15 +4669,15 @@ static gboolean vnc_connection_perform_auth_vencrypt(VncConnection *conn) VNC_DEBUG("Possible VeNCrypt sub-auth %u", auth[i]); } - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return FALSE; vnc_connection_choose_auth(conn, VNC_AUTH_CHOOSE_SUBTYPE, nauth, auth); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return FALSE; VNC_DEBUG("Waiting for VeNCrypt auth subtype"); g_condition_wait(vnc_connection_has_auth_subtype, conn); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return FALSE; VNC_DEBUG("Choose auth %u", priv->auth_subtype); @@ -4753,7 +4750,7 @@ static gboolean vnc_connection_has_auth_type(gpointer data) VncConnection *conn = data; VncConnectionPrivate *priv = conn->priv; - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return TRUE; if (priv->auth_type == VNC_CONNECTION_AUTH_INVALID) return FALSE; @@ -4790,15 +4787,15 @@ static gboolean vnc_connection_perform_auth(VncConnection *conn) VNC_DEBUG("Possible auth %u", auth[i]); } - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return FALSE; vnc_connection_choose_auth(conn, VNC_AUTH_CHOOSE_TYPE, nauth, auth); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return FALSE; VNC_DEBUG("Waiting for auth type"); g_condition_wait(vnc_connection_has_auth_type, conn); - if (priv->coroutine_stop) + if (vnc_connection_has_error(conn)) return FALSE; VNC_DEBUG("Choose auth %u", priv->auth_type);