2011-12-30 08:10:28 +00:00
|
|
|
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (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.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is libguac-client-rdp.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Michael Jumper.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2012-03-05 20:15:35 +00:00
|
|
|
* Matt Hortman
|
2012-05-25 07:02:35 +00:00
|
|
|
* David PHAM-VAN <d.pham-van@ulteo.com> Ulteo SAS - http://www.ulteo.com
|
2012-10-02 21:11:39 +00:00
|
|
|
* Laurent Meunier <laurent@deltalima.net>
|
2011-12-30 08:10:28 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2012-10-31 08:05:43 +00:00
|
|
|
#define _XOPEN_SOURCE 500
|
|
|
|
|
2011-12-30 08:10:28 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-10-31 08:05:43 +00:00
|
|
|
#include <pthread.h>
|
2011-12-30 08:10:28 +00:00
|
|
|
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <freerdp/freerdp.h>
|
2012-01-03 07:31:13 +00:00
|
|
|
#include <freerdp/utils/memory.h>
|
|
|
|
#include <freerdp/cache/bitmap.h>
|
2012-01-08 23:18:31 +00:00
|
|
|
#include <freerdp/cache/brush.h>
|
|
|
|
#include <freerdp/cache/glyph.h>
|
|
|
|
#include <freerdp/cache/palette.h>
|
|
|
|
#include <freerdp/cache/pointer.h>
|
|
|
|
#include <freerdp/cache/offscreen.h>
|
2011-12-30 08:10:28 +00:00
|
|
|
#include <freerdp/channels/channels.h>
|
|
|
|
#include <freerdp/input.h>
|
2012-01-03 23:41:42 +00:00
|
|
|
#include <freerdp/constants.h>
|
2011-12-30 08:10:28 +00:00
|
|
|
|
|
|
|
#include <guacamole/socket.h>
|
|
|
|
#include <guacamole/protocol.h>
|
|
|
|
#include <guacamole/client.h>
|
2012-03-25 20:07:31 +00:00
|
|
|
#include <guacamole/error.h>
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2012-10-28 07:23:44 +00:00
|
|
|
#include "audio.h"
|
2012-11-01 21:26:36 +00:00
|
|
|
#include "wav_encoder.h"
|
2012-10-28 07:23:44 +00:00
|
|
|
|
2012-11-23 02:42:27 +00:00
|
|
|
#ifdef ENABLE_OGG
|
|
|
|
#include "ogg_encoder.h"
|
|
|
|
#endif
|
|
|
|
|
2011-12-30 08:10:28 +00:00
|
|
|
#include "client.h"
|
|
|
|
#include "guac_handlers.h"
|
|
|
|
#include "rdp_keymap.h"
|
2012-01-03 07:31:13 +00:00
|
|
|
#include "rdp_bitmap.h"
|
2012-01-03 21:39:59 +00:00
|
|
|
#include "rdp_glyph.h"
|
|
|
|
#include "rdp_pointer.h"
|
2012-01-04 03:09:33 +00:00
|
|
|
#include "rdp_gdi.h"
|
2012-05-17 20:04:38 +00:00
|
|
|
#include "default_pointer.h"
|
2011-12-30 08:10:28 +00:00
|
|
|
|
|
|
|
/* Client plugin arguments */
|
|
|
|
const char* GUAC_CLIENT_ARGS[] = {
|
|
|
|
"hostname",
|
|
|
|
"port",
|
2012-05-04 08:11:07 +00:00
|
|
|
"domain",
|
2012-02-27 18:36:14 +00:00
|
|
|
"username",
|
|
|
|
"password",
|
|
|
|
"width",
|
|
|
|
"height",
|
2012-05-04 08:11:07 +00:00
|
|
|
"initial-program",
|
|
|
|
"color-depth",
|
2012-11-23 03:07:03 +00:00
|
|
|
"disable-audio",
|
2012-12-26 03:36:19 +00:00
|
|
|
"console",
|
|
|
|
"console-audio",
|
2013-01-16 04:56:59 +00:00
|
|
|
"layout",
|
2011-12-30 08:10:28 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-01-16 04:56:59 +00:00
|
|
|
enum RDP_ARGS_IDX {
|
|
|
|
|
2012-02-27 18:36:14 +00:00
|
|
|
IDX_HOSTNAME,
|
|
|
|
IDX_PORT,
|
2012-05-04 08:11:07 +00:00
|
|
|
IDX_DOMAIN,
|
2012-02-27 18:36:14 +00:00
|
|
|
IDX_USERNAME,
|
|
|
|
IDX_PASSWORD,
|
|
|
|
IDX_WIDTH,
|
|
|
|
IDX_HEIGHT,
|
|
|
|
IDX_INITIAL_PROGRAM,
|
2012-11-23 03:07:03 +00:00
|
|
|
IDX_COLOR_DEPTH,
|
2012-12-26 03:36:19 +00:00
|
|
|
IDX_DISABLE_AUDIO,
|
|
|
|
IDX_CONSOLE,
|
2013-01-16 04:57:45 +00:00
|
|
|
IDX_CONSOLE_AUDIO,
|
2013-01-16 04:56:59 +00:00
|
|
|
IDX_LAYOUT,
|
2013-01-16 04:57:45 +00:00
|
|
|
RDP_ARGS_COUNT
|
2012-02-23 19:27:23 +00:00
|
|
|
};
|
|
|
|
|
2012-03-30 18:26:52 +00:00
|
|
|
int __guac_receive_channel_data(freerdp* rdp_inst, int channelId, uint8* data, int size, int flags, int total_size) {
|
|
|
|
return freerdp_channels_data(rdp_inst, channelId, data, size, flags, total_size);
|
|
|
|
}
|
|
|
|
|
2012-01-03 09:01:33 +00:00
|
|
|
boolean rdp_freerdp_pre_connect(freerdp* instance) {
|
|
|
|
|
|
|
|
rdpContext* context = instance->context;
|
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
|
|
|
rdpChannels* channels = context->channels;
|
|
|
|
rdpBitmap* bitmap;
|
2012-01-03 21:39:59 +00:00
|
|
|
rdpGlyph* glyph;
|
|
|
|
rdpPointer* pointer;
|
2012-01-04 03:09:33 +00:00
|
|
|
rdpPrimaryUpdate* primary;
|
2012-02-08 20:32:27 +00:00
|
|
|
CLRCONV* clrconv;
|
2012-10-28 07:23:44 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
rdp_guac_client_data* guac_client_data =
|
|
|
|
(rdp_guac_client_data*) client->data;
|
2012-02-08 20:32:27 +00:00
|
|
|
|
2012-03-30 18:26:52 +00:00
|
|
|
/* Load clipboard plugin */
|
2012-10-28 01:36:21 +00:00
|
|
|
if (freerdp_channels_load_plugin(channels, instance->settings,
|
|
|
|
"cliprdr", NULL))
|
|
|
|
guac_client_log_error(client, "Failed to load cliprdr plugin.");
|
|
|
|
|
2012-11-23 03:07:03 +00:00
|
|
|
/* If audio enabled, choose an encoder */
|
|
|
|
if (guac_client_data->audio_enabled) {
|
2012-10-28 07:23:44 +00:00
|
|
|
|
2012-11-23 03:07:03 +00:00
|
|
|
/* Choose an encoding */
|
|
|
|
for (i=0; client->info.audio_mimetypes[i] != NULL; i++) {
|
|
|
|
|
|
|
|
const char* mimetype = client->info.audio_mimetypes[i];
|
2012-10-28 07:23:44 +00:00
|
|
|
|
2012-11-23 02:42:27 +00:00
|
|
|
#ifdef ENABLE_OGG
|
2012-11-23 03:07:03 +00:00
|
|
|
/* If Ogg is supported, done. */
|
|
|
|
if (strcmp(mimetype, ogg_encoder->mimetype) == 0) {
|
|
|
|
guac_client_log_info(client, "Loading Ogg Vorbis encoder.");
|
|
|
|
guac_client_data->audio = audio_stream_alloc(client,
|
|
|
|
ogg_encoder);
|
|
|
|
break;
|
|
|
|
}
|
2012-11-23 02:42:27 +00:00
|
|
|
#endif
|
2012-10-28 07:23:44 +00:00
|
|
|
|
2012-11-23 03:07:03 +00:00
|
|
|
/* If wav is supported, done. */
|
|
|
|
if (strcmp(mimetype, wav_encoder->mimetype) == 0) {
|
|
|
|
guac_client_log_info(client, "Loading wav encoder.");
|
|
|
|
guac_client_data->audio = audio_stream_alloc(client,
|
|
|
|
wav_encoder);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-01 21:26:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 03:07:03 +00:00
|
|
|
/* If an encoding is available, load the sound plugin */
|
|
|
|
if (guac_client_data->audio != NULL) {
|
2012-10-28 07:23:44 +00:00
|
|
|
|
2012-11-23 03:07:03 +00:00
|
|
|
/* Load sound plugin */
|
|
|
|
if (freerdp_channels_load_plugin(channels, instance->settings,
|
|
|
|
"guac_rdpsnd", guac_client_data->audio))
|
|
|
|
guac_client_log_error(client,
|
|
|
|
"Failed to load guac_rdpsnd plugin.");
|
2012-10-28 07:23:44 +00:00
|
|
|
|
2012-11-23 03:07:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
guac_client_log_info(client,
|
|
|
|
"No available audio encoding. Sound disabled.");
|
2012-10-28 07:23:44 +00:00
|
|
|
|
2012-11-23 03:07:03 +00:00
|
|
|
} /* end if audio enabled */
|
2012-03-30 18:26:52 +00:00
|
|
|
|
2012-02-08 20:32:27 +00:00
|
|
|
/* Init color conversion structure */
|
|
|
|
clrconv = xnew(CLRCONV);
|
|
|
|
clrconv->alpha = 1;
|
|
|
|
clrconv->invert = 0;
|
|
|
|
clrconv->rgb555 = 0;
|
|
|
|
clrconv->palette = xnew(rdpPalette);
|
|
|
|
((rdp_freerdp_context*) context)->clrconv = clrconv;
|
2012-01-03 09:01:33 +00:00
|
|
|
|
2012-01-08 23:18:31 +00:00
|
|
|
/* Init FreeRDP cache */
|
|
|
|
instance->context->cache = cache_new(instance->settings);
|
|
|
|
|
2012-01-03 09:01:33 +00:00
|
|
|
/* Set up bitmap handling */
|
|
|
|
bitmap = xnew(rdpBitmap);
|
|
|
|
bitmap->size = sizeof(guac_rdp_bitmap);
|
|
|
|
bitmap->New = guac_rdp_bitmap_new;
|
2012-01-03 21:04:50 +00:00
|
|
|
bitmap->Free = guac_rdp_bitmap_free;
|
|
|
|
bitmap->Paint = guac_rdp_bitmap_paint;
|
2012-01-08 23:18:31 +00:00
|
|
|
bitmap->Decompress = guac_rdp_bitmap_decompress;
|
2012-01-03 21:39:59 +00:00
|
|
|
bitmap->SetSurface = guac_rdp_bitmap_setsurface;
|
2012-01-03 09:01:33 +00:00
|
|
|
graphics_register_bitmap(context->graphics, bitmap);
|
2012-03-22 17:27:57 +00:00
|
|
|
xfree(bitmap);
|
2012-01-03 09:01:33 +00:00
|
|
|
|
2012-01-03 21:39:59 +00:00
|
|
|
/* Set up glyph handling */
|
|
|
|
glyph = xnew(rdpGlyph);
|
|
|
|
glyph->size = sizeof(guac_rdp_glyph);
|
|
|
|
glyph->New = guac_rdp_glyph_new;
|
|
|
|
glyph->Free = guac_rdp_glyph_free;
|
|
|
|
glyph->Draw = guac_rdp_glyph_draw;
|
2012-01-09 03:23:37 +00:00
|
|
|
glyph->BeginDraw = guac_rdp_glyph_begindraw;
|
|
|
|
glyph->EndDraw = guac_rdp_glyph_enddraw;
|
2012-01-03 21:39:59 +00:00
|
|
|
graphics_register_glyph(context->graphics, glyph);
|
2012-03-22 17:27:57 +00:00
|
|
|
xfree(glyph);
|
2012-01-03 21:39:59 +00:00
|
|
|
|
|
|
|
/* Set up pointer handling */
|
|
|
|
pointer = xnew(rdpPointer);
|
|
|
|
pointer->size = sizeof(guac_rdp_pointer);
|
|
|
|
pointer->New = guac_rdp_pointer_new;
|
|
|
|
pointer->Free = guac_rdp_pointer_free;
|
|
|
|
pointer->Set = guac_rdp_pointer_set;
|
2012-05-25 07:21:00 +00:00
|
|
|
#ifdef HAVE_RDPPOINTER_SETNULL
|
2012-05-23 10:11:39 +00:00
|
|
|
pointer->SetNull = guac_rdp_pointer_set_null;
|
2012-05-25 07:21:00 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_RDPPOINTER_SETDEFAULT
|
2012-05-23 10:11:39 +00:00
|
|
|
pointer->SetDefault = guac_rdp_pointer_set_default;
|
2012-05-25 07:21:00 +00:00
|
|
|
#endif
|
2012-01-03 21:39:59 +00:00
|
|
|
graphics_register_pointer(context->graphics, pointer);
|
2012-03-22 17:27:57 +00:00
|
|
|
xfree(pointer);
|
2012-01-03 21:39:59 +00:00
|
|
|
|
2012-01-04 03:09:33 +00:00
|
|
|
/* Set up GDI */
|
2012-04-04 00:58:31 +00:00
|
|
|
instance->update->EndPaint = guac_rdp_gdi_end_paint;
|
2012-02-08 20:32:27 +00:00
|
|
|
instance->update->Palette = guac_rdp_gdi_palette_update;
|
2012-02-08 22:16:05 +00:00
|
|
|
instance->update->SetBounds = guac_rdp_gdi_set_bounds;
|
2012-01-04 03:09:33 +00:00
|
|
|
|
2012-02-08 20:32:27 +00:00
|
|
|
primary = instance->update->primary;
|
2012-01-04 03:09:33 +00:00
|
|
|
primary->DstBlt = guac_rdp_gdi_dstblt;
|
|
|
|
primary->PatBlt = guac_rdp_gdi_patblt;
|
|
|
|
primary->ScrBlt = guac_rdp_gdi_scrblt;
|
|
|
|
primary->MemBlt = guac_rdp_gdi_memblt;
|
|
|
|
primary->OpaqueRect = guac_rdp_gdi_opaquerect;
|
|
|
|
|
2012-02-08 23:09:12 +00:00
|
|
|
pointer_cache_register_callbacks(instance->update);
|
2012-01-08 23:18:31 +00:00
|
|
|
glyph_cache_register_callbacks(instance->update);
|
2012-02-08 23:09:12 +00:00
|
|
|
brush_cache_register_callbacks(instance->update);
|
2012-01-08 23:18:31 +00:00
|
|
|
bitmap_cache_register_callbacks(instance->update);
|
2012-02-08 23:09:12 +00:00
|
|
|
offscreen_cache_register_callbacks(instance->update);
|
|
|
|
palette_cache_register_callbacks(instance->update);
|
2012-01-08 23:18:31 +00:00
|
|
|
|
2012-01-03 09:01:33 +00:00
|
|
|
/* Init channels (pre-connect) */
|
|
|
|
if (freerdp_channels_pre_connect(channels, instance)) {
|
|
|
|
guac_protocol_send_error(client->socket, "Error initializing RDP client channel manager");
|
|
|
|
guac_socket_flush(client->socket);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean rdp_freerdp_post_connect(freerdp* instance) {
|
|
|
|
|
|
|
|
rdpContext* context = instance->context;
|
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
|
|
|
rdpChannels* channels = instance->context->channels;
|
|
|
|
|
|
|
|
/* Init channels (post-connect) */
|
|
|
|
if (freerdp_channels_post_connect(channels, instance)) {
|
|
|
|
guac_protocol_send_error(client->socket, "Error initializing RDP client channel manager");
|
|
|
|
guac_socket_flush(client->socket);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Client handlers */
|
|
|
|
client->free_handler = rdp_guac_client_free_handler;
|
|
|
|
client->handle_messages = rdp_guac_client_handle_messages;
|
|
|
|
client->mouse_handler = rdp_guac_client_mouse_handler;
|
|
|
|
client->key_handler = rdp_guac_client_key_handler;
|
2012-04-30 06:28:29 +00:00
|
|
|
client->clipboard_handler = rdp_guac_client_clipboard_handler;
|
2012-01-03 09:01:33 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-12-30 08:10:28 +00:00
|
|
|
void rdp_freerdp_context_new(freerdp* instance, rdpContext* context) {
|
2012-01-03 09:01:33 +00:00
|
|
|
context->channels = freerdp_channels_new();
|
2011-12-30 08:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rdp_freerdp_context_free(freerdp* instance, rdpContext* context) {
|
|
|
|
/* EMPTY */
|
|
|
|
}
|
|
|
|
|
2012-03-21 17:45:40 +00:00
|
|
|
void __guac_rdp_client_load_keymap(guac_client* client,
|
|
|
|
const guac_rdp_keymap* keymap) {
|
|
|
|
|
|
|
|
rdp_guac_client_data* guac_client_data =
|
|
|
|
(rdp_guac_client_data*) client->data;
|
2012-05-01 16:09:16 +00:00
|
|
|
|
2012-03-21 17:45:40 +00:00
|
|
|
/* Get mapping */
|
|
|
|
const guac_rdp_keysym_desc* mapping = keymap->mapping;
|
|
|
|
|
|
|
|
/* If parent exists, load parent first */
|
|
|
|
if (keymap->parent != NULL)
|
|
|
|
__guac_rdp_client_load_keymap(client, keymap->parent);
|
|
|
|
|
|
|
|
/* Log load */
|
2012-03-21 19:35:20 +00:00
|
|
|
guac_client_log_info(client, "Loading keymap \"%s\"", keymap->name);
|
2012-03-21 17:45:40 +00:00
|
|
|
|
|
|
|
/* Load mapping into keymap */
|
|
|
|
while (mapping->keysym != 0) {
|
|
|
|
|
|
|
|
/* Copy mapping */
|
|
|
|
GUAC_RDP_KEYSYM_LOOKUP(guac_client_data->keymap, mapping->keysym) =
|
|
|
|
*mapping;
|
|
|
|
|
|
|
|
/* Next keysym */
|
|
|
|
mapping++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-12-30 08:10:28 +00:00
|
|
|
int guac_client_init(guac_client* client, int argc, char** argv) {
|
|
|
|
|
|
|
|
rdp_guac_client_data* guac_client_data;
|
|
|
|
|
|
|
|
freerdp* rdp_inst;
|
2012-02-27 18:36:14 +00:00
|
|
|
rdpSettings* settings;
|
2011-12-30 08:10:28 +00:00
|
|
|
|
|
|
|
char* hostname;
|
|
|
|
int port = RDP_DEFAULT_PORT;
|
2012-01-03 23:41:42 +00:00
|
|
|
boolean bitmap_cache;
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2012-05-01 16:09:16 +00:00
|
|
|
/**
|
|
|
|
* Selected server-side keymap. Client will be assumed to also use this
|
|
|
|
* keymap. Keys will be sent to server based on client input on a
|
|
|
|
* best-effort basis.
|
|
|
|
*/
|
2013-01-16 04:56:59 +00:00
|
|
|
const guac_rdp_keymap* chosen_keymap;
|
2012-05-01 16:09:16 +00:00
|
|
|
|
2013-01-16 04:57:45 +00:00
|
|
|
if (argc < RDP_ARGS_COUNT) {
|
2012-03-25 20:07:31 +00:00
|
|
|
|
|
|
|
guac_protocol_send_error(client->socket,
|
|
|
|
"Wrong argument count received.");
|
2011-12-30 08:10:28 +00:00
|
|
|
guac_socket_flush(client->socket);
|
2012-03-25 20:07:31 +00:00
|
|
|
|
|
|
|
guac_error = GUAC_STATUS_BAD_ARGUMENT;
|
|
|
|
guac_error_message = "Wrong argument count received";
|
|
|
|
|
2011-12-30 08:10:28 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If port specified, use it */
|
2012-02-23 19:27:23 +00:00
|
|
|
if (argv[IDX_PORT][0] != '\0')
|
|
|
|
port = atoi(argv[IDX_PORT]);
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2012-02-23 19:27:23 +00:00
|
|
|
hostname = argv[IDX_HOSTNAME];
|
2011-12-30 08:10:28 +00:00
|
|
|
|
|
|
|
/* Allocate client data */
|
|
|
|
guac_client_data = malloc(sizeof(rdp_guac_client_data));
|
|
|
|
|
2012-01-03 09:01:33 +00:00
|
|
|
/* Init client */
|
|
|
|
freerdp_channels_global_init();
|
|
|
|
rdp_inst = freerdp_new();
|
|
|
|
rdp_inst->PreConnect = rdp_freerdp_pre_connect;
|
|
|
|
rdp_inst->PostConnect = rdp_freerdp_post_connect;
|
2012-03-30 18:26:52 +00:00
|
|
|
rdp_inst->ReceiveChannelData = __guac_receive_channel_data;
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2012-01-03 09:01:33 +00:00
|
|
|
/* Allocate FreeRDP context */
|
|
|
|
rdp_inst->context_size = sizeof(rdp_freerdp_context);
|
|
|
|
rdp_inst->ContextNew = (pContextNew) rdp_freerdp_context_new;
|
|
|
|
rdp_inst->ContextFree = (pContextFree) rdp_freerdp_context_free;
|
|
|
|
freerdp_context_new(rdp_inst);
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2012-01-03 09:01:33 +00:00
|
|
|
/* Set settings */
|
|
|
|
settings = rdp_inst->settings;
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2012-12-26 03:36:19 +00:00
|
|
|
/* Console */
|
2012-12-26 23:29:54 +00:00
|
|
|
settings->console_session = (strcmp(argv[IDX_CONSOLE], "true") == 0);
|
|
|
|
settings->console_audio = (strcmp(argv[IDX_CONSOLE_AUDIO], "true") == 0);
|
2012-12-26 03:36:19 +00:00
|
|
|
|
2012-01-03 09:05:21 +00:00
|
|
|
/* --no-auth */
|
|
|
|
settings->authentication = false;
|
|
|
|
|
|
|
|
/* --sec rdp */
|
|
|
|
settings->rdp_security = true;
|
|
|
|
settings->tls_security = false;
|
|
|
|
settings->nla_security = false;
|
|
|
|
settings->encryption = true;
|
|
|
|
settings->encryption_method = ENCRYPTION_METHOD_40BIT | ENCRYPTION_METHOD_128BIT | ENCRYPTION_METHOD_FIPS;
|
|
|
|
settings->encryption_level = ENCRYPTION_LEVEL_CLIENT_COMPATIBLE;
|
|
|
|
|
2012-10-22 22:02:58 +00:00
|
|
|
/* Use optimal width unless overridden */
|
|
|
|
settings->width = client->info.optimal_width;
|
2012-02-27 18:36:14 +00:00
|
|
|
if (argv[IDX_WIDTH][0] != '\0')
|
|
|
|
settings->width = atoi(argv[IDX_WIDTH]);
|
2012-10-02 21:09:57 +00:00
|
|
|
|
|
|
|
/* Use default width if given width is invalid. */
|
2012-10-22 22:02:58 +00:00
|
|
|
if (settings->width <= 0) {
|
2012-10-02 21:09:57 +00:00
|
|
|
settings->width = RDP_DEFAULT_WIDTH;
|
|
|
|
guac_client_log_error(client,
|
|
|
|
"Invalid width: \"%s\". Using default of %i.",
|
|
|
|
argv[IDX_WIDTH], settings->width);
|
|
|
|
}
|
2012-02-27 18:36:14 +00:00
|
|
|
|
2013-01-23 09:34:51 +00:00
|
|
|
/* Round width up to nearest multiple of 4 */
|
|
|
|
settings->width = (settings->width + 3) & ~0x3;
|
|
|
|
|
2012-10-22 22:02:58 +00:00
|
|
|
/* Use optimal height unless overridden */
|
|
|
|
settings->height = client->info.optimal_height;
|
2012-02-27 18:36:14 +00:00
|
|
|
if (argv[IDX_HEIGHT][0] != '\0')
|
|
|
|
settings->height = atoi(argv[IDX_HEIGHT]);
|
2012-10-02 21:09:57 +00:00
|
|
|
|
|
|
|
/* Use default height if given height is invalid. */
|
2012-10-22 22:02:58 +00:00
|
|
|
if (settings->height <= 0) {
|
2012-10-02 21:09:57 +00:00
|
|
|
settings->height = RDP_DEFAULT_HEIGHT;
|
|
|
|
guac_client_log_error(client,
|
|
|
|
"Invalid height: \"%s\". Using default of %i.",
|
|
|
|
argv[IDX_WIDTH], settings->height);
|
|
|
|
}
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2012-01-03 09:01:33 +00:00
|
|
|
/* Set hostname */
|
|
|
|
settings->hostname = strdup(hostname);
|
2012-02-28 20:42:58 +00:00
|
|
|
settings->port = port;
|
2012-02-27 18:36:14 +00:00
|
|
|
settings->window_title = strdup(hostname);
|
|
|
|
|
2012-05-04 08:11:07 +00:00
|
|
|
/* Domain */
|
|
|
|
if (argv[IDX_DOMAIN][0] != '\0')
|
|
|
|
settings->domain = strdup(argv[IDX_DOMAIN]);
|
|
|
|
|
|
|
|
/* Username */
|
2012-02-27 18:36:14 +00:00
|
|
|
if (argv[IDX_USERNAME][0] != '\0')
|
2012-05-04 08:11:07 +00:00
|
|
|
settings->username = strdup(argv[IDX_USERNAME]);
|
2012-02-27 18:36:14 +00:00
|
|
|
|
2012-05-04 08:11:07 +00:00
|
|
|
/* Password */
|
2012-02-27 18:36:14 +00:00
|
|
|
if (argv[IDX_PASSWORD][0] != '\0') {
|
2012-05-04 08:11:07 +00:00
|
|
|
settings->password = strdup(argv[IDX_PASSWORD]);
|
2012-02-27 18:36:14 +00:00
|
|
|
settings->autologon = 1;
|
|
|
|
}
|
|
|
|
|
2012-05-04 08:11:07 +00:00
|
|
|
/* Initial program */
|
2012-02-27 18:36:14 +00:00
|
|
|
if (argv[IDX_INITIAL_PROGRAM][0] != '\0')
|
2012-05-04 08:11:07 +00:00
|
|
|
settings->shell = strdup(argv[IDX_INITIAL_PROGRAM]);
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2012-09-28 05:04:33 +00:00
|
|
|
/* Session color depth */
|
2012-10-02 21:09:57 +00:00
|
|
|
settings->color_depth = RDP_DEFAULT_DEPTH;
|
2012-08-31 11:07:05 +00:00
|
|
|
if (argv[IDX_COLOR_DEPTH][0] != '\0')
|
|
|
|
settings->color_depth = atoi(argv[IDX_COLOR_DEPTH]);
|
2012-10-02 21:09:57 +00:00
|
|
|
|
|
|
|
/* Use default depth if given depth is invalid. */
|
|
|
|
if (settings->color_depth == 0) {
|
|
|
|
settings->color_depth = RDP_DEFAULT_DEPTH;
|
|
|
|
guac_client_log_error(client,
|
|
|
|
"Invalid color-depth: \"%s\". Using default of %i.",
|
|
|
|
argv[IDX_WIDTH], settings->color_depth);
|
|
|
|
}
|
2012-08-31 11:07:05 +00:00
|
|
|
|
2012-11-23 03:07:03 +00:00
|
|
|
/* Audio enable/disable */
|
|
|
|
guac_client_data->audio_enabled =
|
|
|
|
(strcmp(argv[IDX_DISABLE_AUDIO], "true") != 0);
|
|
|
|
|
2012-01-03 23:41:42 +00:00
|
|
|
/* Order support */
|
|
|
|
bitmap_cache = settings->bitmap_cache;
|
|
|
|
settings->os_major_type = OSMAJORTYPE_UNSPECIFIED;
|
|
|
|
settings->os_minor_type = OSMINORTYPE_UNSPECIFIED;
|
|
|
|
settings->order_support[NEG_DSTBLT_INDEX] = true;
|
2012-03-07 21:57:49 +00:00
|
|
|
settings->order_support[NEG_PATBLT_INDEX] = false; /* PATBLT not yet supported */
|
2012-01-03 23:41:42 +00:00
|
|
|
settings->order_support[NEG_SCRBLT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_OPAQUE_RECT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_DRAWNINEGRID_INDEX] = false;
|
|
|
|
settings->order_support[NEG_MULTIDSTBLT_INDEX] = false;
|
|
|
|
settings->order_support[NEG_MULTIPATBLT_INDEX] = false;
|
|
|
|
settings->order_support[NEG_MULTISCRBLT_INDEX] = false;
|
|
|
|
settings->order_support[NEG_MULTIOPAQUERECT_INDEX] = false;
|
|
|
|
settings->order_support[NEG_MULTI_DRAWNINEGRID_INDEX] = false;
|
|
|
|
settings->order_support[NEG_LINETO_INDEX] = false;
|
|
|
|
settings->order_support[NEG_POLYLINE_INDEX] = false;
|
|
|
|
settings->order_support[NEG_MEMBLT_INDEX] = bitmap_cache;
|
|
|
|
settings->order_support[NEG_MEM3BLT_INDEX] = false;
|
|
|
|
settings->order_support[NEG_MEMBLT_V2_INDEX] = bitmap_cache;
|
|
|
|
settings->order_support[NEG_MEM3BLT_V2_INDEX] = false;
|
|
|
|
settings->order_support[NEG_SAVEBITMAP_INDEX] = false;
|
2012-03-07 21:57:49 +00:00
|
|
|
settings->order_support[NEG_GLYPH_INDEX_INDEX] = true;
|
|
|
|
settings->order_support[NEG_FAST_INDEX_INDEX] = true;
|
|
|
|
settings->order_support[NEG_FAST_GLYPH_INDEX] = true;
|
2012-01-03 23:41:42 +00:00
|
|
|
settings->order_support[NEG_POLYGON_SC_INDEX] = false;
|
|
|
|
settings->order_support[NEG_POLYGON_CB_INDEX] = false;
|
|
|
|
settings->order_support[NEG_ELLIPSE_SC_INDEX] = false;
|
|
|
|
settings->order_support[NEG_ELLIPSE_CB_INDEX] = false;
|
|
|
|
|
2012-01-03 09:01:33 +00:00
|
|
|
/* Store client data */
|
2011-12-30 08:10:28 +00:00
|
|
|
guac_client_data->rdp_inst = rdp_inst;
|
|
|
|
guac_client_data->mouse_button_mask = 0;
|
|
|
|
guac_client_data->current_surface = GUAC_DEFAULT_LAYER;
|
2012-04-30 06:33:27 +00:00
|
|
|
guac_client_data->clipboard = NULL;
|
2012-10-28 07:23:44 +00:00
|
|
|
guac_client_data->audio = NULL;
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2012-11-01 04:52:16 +00:00
|
|
|
/* Recursive attribute for locks */
|
2012-10-31 08:05:43 +00:00
|
|
|
pthread_mutexattr_init(&(guac_client_data->attributes));
|
|
|
|
pthread_mutexattr_settype(&(guac_client_data->attributes),
|
|
|
|
PTHREAD_MUTEX_RECURSIVE);
|
2012-11-01 04:52:16 +00:00
|
|
|
|
|
|
|
/* Init update lock */
|
2012-10-31 08:05:43 +00:00
|
|
|
pthread_mutex_init(&(guac_client_data->update_lock),
|
|
|
|
&(guac_client_data->attributes));
|
|
|
|
|
2012-11-01 04:52:16 +00:00
|
|
|
/* Init RDP lock */
|
|
|
|
pthread_mutex_init(&(guac_client_data->rdp_lock),
|
|
|
|
&(guac_client_data->attributes));
|
|
|
|
|
2012-03-21 17:45:40 +00:00
|
|
|
/* Clear keysym state mapping and keymap */
|
|
|
|
memset(guac_client_data->keysym_state, 0,
|
|
|
|
sizeof(guac_rdp_keysym_state_map));
|
|
|
|
|
|
|
|
memset(guac_client_data->keymap, 0,
|
|
|
|
sizeof(guac_rdp_static_keymap));
|
2012-03-21 02:43:40 +00:00
|
|
|
|
2011-12-30 08:10:28 +00:00
|
|
|
client->data = guac_client_data;
|
2012-03-21 17:45:40 +00:00
|
|
|
((rdp_freerdp_context*) rdp_inst->context)->client = client;
|
|
|
|
|
2013-01-16 04:56:59 +00:00
|
|
|
/* Pick keymap based on argument */
|
|
|
|
if (argv[IDX_LAYOUT][0] != '\0') {
|
|
|
|
|
|
|
|
/* US English Qwerty */
|
|
|
|
if (strcmp("en-us-qwerty", argv[IDX_LAYOUT]) == 0)
|
|
|
|
chosen_keymap = &rdp_guac_keymap_en_us;
|
|
|
|
|
|
|
|
/* US English Qwerty */
|
|
|
|
if (strcmp("en-us-qwerty", argv[IDX_LAYOUT]) == 0)
|
|
|
|
chosen_keymap = &rdp_guac_keymap_en_us;
|
|
|
|
|
|
|
|
else
|
|
|
|
chosen_keymap = &rdp_guac_keymap_en_us;
|
|
|
|
}
|
|
|
|
|
2012-03-21 17:45:40 +00:00
|
|
|
/* Load keymap into client */
|
2012-05-01 16:09:16 +00:00
|
|
|
__guac_rdp_client_load_keymap(client, chosen_keymap);
|
|
|
|
|
|
|
|
/* Set server-side keymap */
|
|
|
|
settings->kbd_layout = chosen_keymap->freerdp_keyboard_layout;
|
2011-12-30 08:10:28 +00:00
|
|
|
|
|
|
|
/* Connect to RDP server */
|
|
|
|
if (!freerdp_connect(rdp_inst)) {
|
2012-03-25 20:07:31 +00:00
|
|
|
|
|
|
|
guac_protocol_send_error(client->socket,
|
|
|
|
"Error connecting to RDP server");
|
2011-12-30 08:10:28 +00:00
|
|
|
guac_socket_flush(client->socket);
|
2012-03-25 20:07:31 +00:00
|
|
|
|
|
|
|
guac_error = GUAC_STATUS_BAD_STATE;
|
|
|
|
guac_error_message = "Error connecting to RDP server";
|
|
|
|
|
2011-12-30 08:10:28 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-03-26 04:49:58 +00:00
|
|
|
/* Send connection name */
|
|
|
|
guac_protocol_send_name(client->socket, settings->window_title);
|
|
|
|
|
2012-04-06 05:38:10 +00:00
|
|
|
/* Send size */
|
|
|
|
guac_protocol_send_size(client->socket, GUAC_DEFAULT_LAYER,
|
|
|
|
settings->width, settings->height);
|
|
|
|
|
2012-04-06 05:55:46 +00:00
|
|
|
/* Create glyph surfaces */
|
|
|
|
guac_client_data->opaque_glyph_surface = cairo_image_surface_create(
|
2012-04-06 05:38:10 +00:00
|
|
|
CAIRO_FORMAT_RGB24, settings->width, settings->height);
|
|
|
|
|
2012-04-06 05:55:46 +00:00
|
|
|
guac_client_data->trans_glyph_surface = cairo_image_surface_create(
|
|
|
|
CAIRO_FORMAT_ARGB32, settings->width, settings->height);
|
2012-04-06 05:38:10 +00:00
|
|
|
|
2012-05-17 02:52:43 +00:00
|
|
|
/* Set default pointer */
|
2012-05-25 07:21:00 +00:00
|
|
|
guac_rdp_set_default_pointer(client);
|
2012-05-17 02:52:43 +00:00
|
|
|
|
2011-12-30 08:10:28 +00:00
|
|
|
/* Success */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|