[gnome-remote-desktop] rdp: Use internal enum for RDP errors



commit 1feed3d6af706deeca45564c415d034a7aa653fe
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Wed Jan 12 14:36:15 2022 +0100

    rdp: Use internal enum for RDP errors
    
    When performing damage detection on the GPU in the future, some API
    will be used.
    For NVIDIA GPUs, this will be CUDA. For other GPUs, similar APIs will
    be used.
    Although these API calls usually never fail, there is no guarantee,
    that this will always be the case.
    Such cases are rare, but need to be handled. The easiest thing to do is
    to simply end the session.
    
    Currently, this is done using the internal notify_error() API in
    session-rdp.
    However, this requires the knowledge of the FreeRDP error code and
    including FreeRDP headers in certain classes, but it can lead to
    compilation errors due to name collisions.
    
    To take care of this problem, use an internal enum for RDP errors and
    translate these errors into RDP errors in session-rdp.

 src/grd-rdp-graphics-pipeline.c |  6 +++---
 src/grd-session-rdp.c           | 17 ++++++++++++++---
 src/grd-session-rdp.h           | 11 +++++++++--
 3 files changed, 26 insertions(+), 8 deletions(-)
---
diff --git a/src/grd-rdp-graphics-pipeline.c b/src/grd-rdp-graphics-pipeline.c
index 37dc9eb8..a5e4dda5 100644
--- a/src/grd-rdp-graphics-pipeline.c
+++ b/src/grd-rdp-graphics-pipeline.c
@@ -1002,7 +1002,7 @@ rdpgfx_caps_advertise (RdpgfxServerContext             *rdpgfx_context,
                  "CapsAdvertise PDU (RDPGFX: initialized, initial "
                  "version < 103)");
       grd_session_rdp_notify_error (graphics_pipeline->session_rdp,
-                                    ERRINFO_GRAPHICS_SUBSYSTEM_FAILED);
+                                    GRD_SESSION_RDP_ERROR_BAD_CAPS);
 
       return CHANNEL_RC_ALREADY_INITIALIZED;
     }
@@ -1013,7 +1013,7 @@ rdpgfx_caps_advertise (RdpgfxServerContext             *rdpgfx_context,
       g_warning ("[RDP.RDPGFX] CapsAdvertise PDU does NOT contain any supported "
                  "capability sets");
       grd_session_rdp_notify_error (graphics_pipeline->session_rdp,
-                                    ERRINFO_GRAPHICS_SUBSYSTEM_FAILED);
+                                    GRD_SESSION_RDP_ERROR_BAD_CAPS);
 
       return CHANNEL_RC_UNSUPPORTED_VERSION;
     }
@@ -1196,7 +1196,7 @@ grd_rdp_graphics_pipeline_maybe_init (GrdRdpGraphicsPipeline *graphics_pipeline)
       g_warning ("[RDP.RDPGFX] Failed to open Graphics Pipeline. The client "
                  "probably falsely advertised GFX support");
       grd_session_rdp_notify_error (graphics_pipeline->session_rdp,
-                                    ERRINFO_GRAPHICS_SUBSYSTEM_FAILED);
+                                    GRD_SESSION_RDP_ERROR_GRAPHICS_SUBSYSTEM_FAILED);
       return;
     }
 
diff --git a/src/grd-session-rdp.c b/src/grd-session-rdp.c
index 027b43f7..c2d00873 100644
--- a/src/grd-session-rdp.c
+++ b/src/grd-session-rdp.c
@@ -617,10 +617,21 @@ maybe_queue_close_session_idle (GrdSessionRdp *session_rdp)
 }
 
 void
-grd_session_rdp_notify_error (GrdSessionRdp *session_rdp,
-                              uint32_t       error_info)
+grd_session_rdp_notify_error (GrdSessionRdp      *session_rdp,
+                              GrdSessionRdpError  error_info)
 {
-  session_rdp->rdp_error_info = error_info;
+  switch (error_info)
+    {
+    case GRD_SESSION_RDP_ERROR_NONE:
+      g_assert_not_reached ();
+      break;
+    case GRD_SESSION_RDP_ERROR_BAD_CAPS:
+      session_rdp->rdp_error_info = ERRINFO_BAD_CAPABILITIES;
+      break;
+    case GRD_SESSION_RDP_ERROR_GRAPHICS_SUBSYSTEM_FAILED:
+      session_rdp->rdp_error_info = ERRINFO_GRAPHICS_SUBSYSTEM_FAILED;
+      break;
+    }
 
   unset_rdp_peer_flag (session_rdp, RDP_PEER_ACTIVATED);
   maybe_queue_close_session_idle (session_rdp);
diff --git a/src/grd-session-rdp.h b/src/grd-session-rdp.h
index 48deceb6..49512c50 100644
--- a/src/grd-session-rdp.h
+++ b/src/grd-session-rdp.h
@@ -32,6 +32,13 @@ G_DECLARE_FINAL_TYPE (GrdSessionRdp,
                       GRD, SESSION_RDP,
                       GrdSession)
 
+typedef enum _GrdSessionRdpError
+{
+  GRD_SESSION_RDP_ERROR_NONE,
+  GRD_SESSION_RDP_ERROR_BAD_CAPS,
+  GRD_SESSION_RDP_ERROR_GRAPHICS_SUBSYSTEM_FAILED,
+} GrdSessionRdpError;
+
 GrdSessionRdp *grd_session_rdp_new (GrdRdpServer      *rdp_server,
                                     GSocketConnection *connection,
 #ifdef HAVE_HWACCEL_NVIDIA
@@ -39,8 +46,8 @@ GrdSessionRdp *grd_session_rdp_new (GrdRdpServer      *rdp_server,
 #endif /* HAVE_HWACCEL_NVIDIA */
                                     int                reserved);
 
-void grd_session_rdp_notify_error (GrdSessionRdp *session_rdp,
-                                   uint32_t       error_info);
+void grd_session_rdp_notify_error (GrdSessionRdp      *session_rdp,
+                                   GrdSessionRdpError  error_info);
 
 void grd_session_rdp_notify_graphics_pipeline_reset (GrdSessionRdp *session_rdp);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]