Blame SOURCES/0007-conn-Use-vnc_connection_has_error-extensively.patch

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