You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by jm...@apache.org on 2016/06/02 18:45:12 UTC

[05/26] incubator-guacamole-server git commit: GUACAMOLE-25: Convert guac_client pointer to/from a string for sake of FreeRDP's DVC API.

GUACAMOLE-25: Convert guac_client pointer to/from a string for sake of FreeRDP's DVC API.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/36cc9f49
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/36cc9f49
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/36cc9f49

Branch: refs/heads/master
Commit: 36cc9f492fb0424d32aaa041383d8e8ab8e3cd90
Parents: 21ab9d7
Author: Michael Jumper <mj...@apache.org>
Authored: Sat Apr 16 17:13:39 2016 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Wed May 25 13:50:28 2016 -0700

----------------------------------------------------------------------
 src/protocols/rdp/Makefile.am          |  5 ++-
 src/protocols/rdp/audio_input.c        |  5 +++
 src/protocols/rdp/guac_ai/ai_service.c |  7 ++--
 src/protocols/rdp/ptr_string.c         | 55 ++++++++++++++++++++++++++++
 src/protocols/rdp/ptr_string.h         | 57 +++++++++++++++++++++++++++++
 5 files changed, 124 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/36cc9f49/src/protocols/rdp/Makefile.am
----------------------------------------------------------------------
diff --git a/src/protocols/rdp/Makefile.am b/src/protocols/rdp/Makefile.am
index 44f248a..0ac074a 100644
--- a/src/protocols/rdp/Makefile.am
+++ b/src/protocols/rdp/Makefile.am
@@ -27,6 +27,7 @@ libguac_client_rdp_la_SOURCES = \
     audio_input.c               \
     client.c                    \
     input.c                     \
+    ptr_string.c                \
     rdp.c                       \
     rdp_bitmap.c                \
     rdp_cliprdr.c               \
@@ -46,7 +47,8 @@ libguac_client_rdp_la_SOURCES = \
     user.c
 
 guacai_sources =         \
-    guac_ai/ai_service.c
+    guac_ai/ai_service.c \
+	ptr_string.c
 
 guacsvc_sources =          \
     guac_svc/svc_service.c \
@@ -87,6 +89,7 @@ noinst_HEADERS =                             \
     audio_input.h                            \
     client.h                                 \
     input.h                                  \
+    ptr_string.h                             \
     rdp.h                                    \
     rdp_bitmap.h                             \
     rdp_cliprdr.h                            \

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/36cc9f49/src/protocols/rdp/audio_input.c
----------------------------------------------------------------------
diff --git a/src/protocols/rdp/audio_input.c b/src/protocols/rdp/audio_input.c
index 8233184..b5c3f96 100644
--- a/src/protocols/rdp/audio_input.c
+++ b/src/protocols/rdp/audio_input.c
@@ -19,6 +19,8 @@
 
 #include "config.h"
 #include "audio_input.h"
+#include "ptr_string.h"
+#include "rdp.h"
 
 #include <freerdp/freerdp.h>
 #include <freerdp/channels/channels.h>
@@ -63,11 +65,14 @@ int guac_rdp_audio_end_handler(guac_user* user, guac_stream* stream) {
 
 void guac_rdp_audio_load_plugin(rdpContext* context) {
 
+    guac_client* client = ((rdp_freerdp_context*) context)->client;
+
     /* Add "AUDIO_INPUT" channel */
     ADDIN_ARGV* args = malloc(sizeof(ADDIN_ARGV));
     args->argc = 1;
     args->argv = malloc(sizeof(char**) * 1);
     args->argv[0] = strdup("guacai");
+    args->argv[1] = guac_rdp_ptr_to_string(client);
     freerdp_dynamic_channel_collection_add(context->settings, args);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/36cc9f49/src/protocols/rdp/guac_ai/ai_service.c
----------------------------------------------------------------------
diff --git a/src/protocols/rdp/guac_ai/ai_service.c b/src/protocols/rdp/guac_ai/ai_service.c
index 15490a0..c6ff47b 100644
--- a/src/protocols/rdp/guac_ai/ai_service.c
+++ b/src/protocols/rdp/guac_ai/ai_service.c
@@ -20,6 +20,7 @@
 #include "config.h"
 
 #include "ai_service.h"
+#include "ptr_string.h"
 #include "rdp.h"
 
 #include <stdlib.h>
@@ -41,10 +42,8 @@
  */
 int DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) {
 
-    rdpSettings* settings = pEntryPoints->GetRdpSettings(pEntryPoints);
-    freerdp* instance = settings->instance;
-    rdpContext* context = instance->context;
-    guac_client* client = ((rdp_freerdp_context*) context)->client;
+    ADDIN_ARGV* args = pEntryPoints->GetPluginData(pEntryPoints);
+    guac_client* client = (guac_client*) guac_rdp_string_to_ptr(args->argv[1]);
 
     /* STUB */
     guac_client_log(client, GUAC_LOG_DEBUG,

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/36cc9f49/src/protocols/rdp/ptr_string.c
----------------------------------------------------------------------
diff --git a/src/protocols/rdp/ptr_string.c b/src/protocols/rdp/ptr_string.c
new file mode 100644
index 0000000..1e79121
--- /dev/null
+++ b/src/protocols/rdp/ptr_string.c
@@ -0,0 +1,55 @@
+/*
+ * 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 "config.h"
+#include "ptr_string.h"
+
+#include <guacamole/client.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/**
+ * The maximum number of bytes required to represent a pointer printed using
+ * printf()'s "%p". This will be the size of the hex prefix ("0x"), null
+ * terminator, plus two bytes for every byte required by a pointer.
+ */
+#define GUAC_RDP_PTR_STRING_LENGTH (sizeof("0x") + (sizeof(void*) * 2))
+
+char* guac_rdp_ptr_to_string(void* data) {
+
+    /* Convert pointer to string */
+    char* str = malloc(GUAC_RDP_PTR_STRING_LENGTH);
+    sprintf(str, "%p", data);
+
+    return str;
+
+}
+
+void* guac_rdp_string_to_ptr(const char* str) {
+
+    void* data;
+
+    /* Convert string to pointer */
+    sscanf(str, "%p", &data);
+
+    return data;
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/36cc9f49/src/protocols/rdp/ptr_string.h
----------------------------------------------------------------------
diff --git a/src/protocols/rdp/ptr_string.h b/src/protocols/rdp/ptr_string.h
new file mode 100644
index 0000000..6b27721
--- /dev/null
+++ b/src/protocols/rdp/ptr_string.h
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+#ifndef GUAC_RDP_PTR_STRING_H
+#define GUAC_RDP_PTR_STRING_H
+
+#include "config.h"
+
+#include <guacamole/client.h>
+
+/**
+ * Converts the given string back into a void pointer. The string MUST have
+ * been produced via guac_rdp_ptr_to_string().
+ *
+ * @param str
+ *     The string to convert back to a pointer.
+ *
+ * @return
+ *     The pointer value of the given string, as originally passed to
+ *     guac_rdp_ptr_to_string().
+ */
+void* guac_rdp_string_to_ptr(const char* str);
+
+/**
+ * Converts a void pointer into a string representation, safe for use with
+ * parts of the FreeRDP API which provide only for passing arbitrary strings,
+ * despite being within the same memory area. The returned string must
+ * eventually be freed with a call to free().
+ *
+ * @param data
+ *     The void pointer to convert to a string.
+ *
+ * @return
+ *     A newly-allocated string containing the string representation of the
+ *     given void pointer. This string must eventually be freed with a call to
+ *     free().
+ */
+char* guac_rdp_ptr_to_string(void* data);
+
+#endif
+