From 685e6c3f471c226b43464212238731c7a86dbe99 Mon Sep 17 00:00:00 2001 From: Mihai Moldovan Date: Thu, 20 Jul 2023 02:54:58 +0200 Subject: src/rda_x2go.{c,h}: add generic protocol support. X2Go supports both NX and KDrive sessions, so parse the session ID (X2GO_SESSION) to find out what protocol the session uses. --- src/rda_x2go.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/rda_x2go.h | 6 ++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/src/rda_x2go.c b/src/rda_x2go.c index 7b8cb6c..76f7652 100644 --- a/src/rda_x2go.c +++ b/src/rda_x2go.c @@ -25,18 +25,102 @@ #include #include +#include +#include #ifdef WITH_REMOTE_AWARENESS_X2GO +const rda_protocol_t +rda_supported_protocols_x2go[] = { RDA_PROTOCOL_NX, RDA_PROTOCOL_KDRIVE }; +const gsize +rda_supported_protocols_x2go_len = static_arr_size(rda_supported_protocols_x2go); + +static gboolean +rda_x2go_session_is_kdrive (const gchar *session_id) +{ + gboolean ret = FALSE; + const gchar *ptr = session_id; + + /* Sanity check. */ + if (!(ptr)) + { + return (ret); + } + + /* Skip user name. */ + while ((ptr) && (*(ptr)) && ('-' != (*(ptr)))) + { + ++ptr; + } + + if ((!(ptr)) || (!(*(ptr++)))) + { + return (ret); + } + + /* Skip port. */ + while ((ptr) && (*(ptr)) && ('-' != (*(ptr)))) + { + ++ptr; + } + + if ((!(ptr)) || (!(*(ptr++)))) + { + return (ret); + } + + /* Skip date. */ + while ((ptr) && (*(ptr)) && ('_' != (*(ptr)))) + { + ++ptr; + } + + if ((!(ptr)) || (!(*(ptr++)))) + { + return (ret); + } + + /* Don't supply a null pointer to strncmp() by accident. */ + if (!(ptr)) + { + return (ret); + } + + /* Check for "st". */ + if (!(strncmp("st", ptr, 2))) + { + ptr += 2; + + /* + * Next character must be 'K' for KDrive sessions. + * Note that this might change in future versions. + */ + if ((ptr) && ('K' == (*(ptr)))) + { + ret = TRUE; + } + } + + return (ret); +} + gboolean rda_session_is_x2go (void) { if (remote_technology == REMOTE_TECHNOLOGY_X2GO) return TRUE; - if (g_getenv("X2GO_SESSION")) + const gchar *session_id = g_getenv("X2GO_SESSION"); + if (session_id) { remote_technology = REMOTE_TECHNOLOGY_X2GO; + rda_protocol = RDA_PROTOCOL_NX; + + if (rda_x2go_session_is_kdrive(session_id)) + { + rda_protocol = RDA_PROTOCOL_KDRIVE; + } + return TRUE; } diff --git a/src/rda_x2go.h b/src/rda_x2go.h index 5759e79..fc9c986 100644 --- a/src/rda_x2go.h +++ b/src/rda_x2go.h @@ -27,9 +27,15 @@ #include #include +#include #ifdef WITH_REMOTE_AWARENESS_X2GO +extern const rda_protocol_t +rda_supported_protocols_x2go[]; +extern const gsize +rda_supported_protocols_x2go_len; + gboolean rda_session_is_x2go (void); -- cgit v1.2.3