necouchman commented on a change in pull request #243: GUACAMOLE-249: Migrate 
to FreeRDP 2.x
URL: https://github.com/apache/guacamole-server/pull/243#discussion_r363565570
 
 

 ##########
 File path: src/protocols/rdp/channels/cliprdr.c
 ##########
 @@ -0,0 +1,601 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "channels/cliprdr.h"
+#include "client.h"
+#include "common/clipboard.h"
+#include "common/iconv.h"
+#include "plugins/channels.h"
+#include "rdp.h"
+
+#include <freerdp/client/cliprdr.h>
+#include <freerdp/event.h>
+#include <freerdp/freerdp.h>
+#include <guacamole/client.h>
+#include <guacamole/stream.h>
+#include <guacamole/user.h>
+#include <winpr/wtsapi.h>
+#include <winpr/wtypes.h>
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+/**
+ * Sends a Format List PDU to the RDP server containing the formats of
+ * clipboard data supported. This PDU is used both to indicate the general
+ * clipboard formats supported at the begining of an RDP session and to inform
+ * the RDP server that new clipboard data is available within the listed
+ * formats.
+ *
+ * @param cliprdr
+ *     The CliprdrClientContext structure used by FreeRDP to handle the
+ *     CLIPRDR channel for the current RDP session.
+ *
+ * @return
+ *     CHANNEL_RC_OK (zero) if the Format List PDU was sent successfully, an
+ *     error code (non-zero) otherwise.
+ */
+static UINT guac_rdp_cliprdr_send_format_list(CliprdrClientContext* cliprdr) {
+
+    /* This function is only invoked within FreeRDP-specific handlers for
+     * CLIPRDR, which are not assigned, and thus not callable, until after the
+     * relevant guac_rdp_clipboard structure is allocated and associated with
+     * the CliprdrClientContext */
+    guac_rdp_clipboard* clipboard = (guac_rdp_clipboard*) cliprdr->custom;
+    assert(clipboard != NULL);
+
+    /* We support CP-1252 and UTF-16 text */
+    CLIPRDR_FORMAT_LIST format_list = {
+        .formats = (CLIPRDR_FORMAT[]) {
+            { .formatId = CF_TEXT },
+            { .formatId = CF_UNICODETEXT }
+        },
+        .numFormats = 2
+    };
+
+    guac_client_log(clipboard->client, GUAC_LOG_TRACE, "CLIPRDR: Sending "
+            "format list");
+
+    return cliprdr->ClientFormatList(cliprdr, &format_list);
+
+}
+
+/**
+ * Sends a Clipboard Capabilities PDU to the RDP server describing the features
+ * of the CLIPRDR channel that are supported by the client.
+ *
+ * @param cliprdr
+ *     The CliprdrClientContext structure used by FreeRDP to handle the
+ *     CLIPRDR channel for the current RDP session.
+ *
+ * @return
+ *     CHANNEL_RC_OK (zero) if the Clipboard Capabilities PDU was sent
+ *     successfully, an error code (non-zero) otherwise.
+ */
+static UINT guac_rdp_cliprdr_send_capabilities(CliprdrClientContext* cliprdr) {
+
+    CLIPRDR_GENERAL_CAPABILITY_SET cap_set = {
+        .capabilitySetType = CB_CAPSTYPE_GENERAL, /* CLIPRDR specification 
requires that this is CB_CAPSTYPE_GENERAL, the only defined set type */
+        .capabilitySetLength = 12, /* The size of the capability set within 
the PDU - for CB_CAPSTYPE_GENERAL, this is ALWAYS 12 bytes */
+        .version = CB_CAPS_VERSION_2, /* The version of the CLIPRDR 
specification supported */
+        .generalFlags = CB_USE_LONG_FORMAT_NAMES /* Bitwise OR of all 
supported feature flags */
+    };
+
+    CLIPRDR_CAPABILITIES caps = {
+        .cCapabilitiesSets = 1,
+        .capabilitySets = (CLIPRDR_CAPABILITY_SET*) &cap_set
+    };
+
+    return cliprdr->ClientCapabilities(cliprdr, &caps);
+
+}
+
+/**
+ * Callback invoked by the FreeRDP CLIPRDR plugin for received Monitor Ready
+ * PDUs. The Monitor Ready PDU is sent by the RDP server only during
+ * initialization of the CLIPRDR channel. It is part of the CLIPRDR channel
+ * handshake and indicates that the RDP server's handling of clipboard
+ * redirection is ready to proceed.
+ *
+ * @param cliprdr
+ *     The CliprdrClientContext structure used by FreeRDP to handle the CLIPRDR
+ *     channel for the current RDP session.
+ *
+ * @param monitor_ready
+ *     The CLIPRDR_MONITOR_READY structure representing the Monitor Ready PDU
+ *     that was received.
+ *
+ * @return
+ *     CHANNEL_RC_OK (zero) if the PDU was handled successfully, an error code
+ *     (non-zero) otherwise.
+ */
+static UINT guac_rdp_cliprdr_monitor_ready(CliprdrClientContext* cliprdr,
+        const CLIPRDR_MONITOR_READY* monitor_ready) {
+
+    /* FreeRDP-specific handlers for CLIPRDR are not assigned, and thus not
+     * callable, until after the relevant guac_rdp_clipboard structure is
+     * allocated and associated with the CliprdrClientContext */
+    guac_rdp_clipboard* clipboard = (guac_rdp_clipboard*) cliprdr->custom;
+    assert(clipboard != NULL);
+
+    guac_client_log(clipboard->client, GUAC_LOG_TRACE, "CLIPRDR: Received "
+            "monitor ready.");
+
+    /* Respond with capabilities and supported format list */
+    guac_rdp_cliprdr_send_capabilities(cliprdr);
+    return guac_rdp_cliprdr_send_format_list(cliprdr);
+
+}
+
+/**
+ * Sends a Format Data Request PDU to the RDP server, requesting that available
+ * clipboard data be sent to the client in the specified format. This PDU is
+ * sent when the server indicating that clipboard data is available via a
 
 Review comment:
   indicating -> indicates

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to