2013-12-29 04:53:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Glyptodon LLC
|
2011-12-30 08:10:28 +00:00
|
|
|
*
|
2013-12-29 04:53:12 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2011-12-30 08:10:28 +00:00
|
|
|
*
|
2013-12-29 04:53:12 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2011-12-30 08:10:28 +00:00
|
|
|
*
|
2013-12-29 04:53:12 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2012-10-31 08:05:43 +00:00
|
|
|
#define _XOPEN_SOURCE 500
|
|
|
|
|
2014-01-01 22:44:28 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "client.h"
|
|
|
|
#include "guac_handlers.h"
|
2014-01-07 00:21:23 +00:00
|
|
|
#include "guac_pointer_cursor.h"
|
2014-01-01 22:44:28 +00:00
|
|
|
#include "rdp_bitmap.h"
|
|
|
|
#include "rdp_gdi.h"
|
|
|
|
#include "rdp_glyph.h"
|
|
|
|
#include "rdp_keymap.h"
|
|
|
|
#include "rdp_pointer.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <pthread.h>
|
2011-12-30 08:10:28 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
|
2012-01-03 07:31:13 +00:00
|
|
|
#include <freerdp/cache/bitmap.h>
|
2012-01-08 23:18:31 +00:00
|
|
|
#include <freerdp/cache/brush.h>
|
|
|
|
#include <freerdp/cache/glyph.h>
|
2014-01-01 22:44:28 +00:00
|
|
|
#include <freerdp/cache/offscreen.h>
|
2012-01-08 23:18:31 +00:00
|
|
|
#include <freerdp/cache/palette.h>
|
|
|
|
#include <freerdp/cache/pointer.h>
|
2013-07-19 04:52:40 +00:00
|
|
|
#include <freerdp/channels/channels.h>
|
2012-01-03 23:41:42 +00:00
|
|
|
#include <freerdp/constants.h>
|
2014-01-01 22:44:28 +00:00
|
|
|
#include <freerdp/freerdp.h>
|
|
|
|
#include <freerdp/input.h>
|
|
|
|
#include <guacamole/audio.h>
|
|
|
|
#include <guacamole/client.h>
|
|
|
|
#include <guacamole/error.h>
|
|
|
|
#include <guacamole/protocol.h>
|
|
|
|
#include <guacamole/socket.h>
|
2013-07-18 16:34:02 +00:00
|
|
|
|
2013-07-17 18:54:24 +00:00
|
|
|
#ifdef ENABLE_WINPR
|
|
|
|
#include <winpr/wtypes.h>
|
|
|
|
#else
|
|
|
|
#include "compat/winpr-wtypes.h"
|
|
|
|
#endif
|
|
|
|
|
2014-01-01 22:44:28 +00:00
|
|
|
#ifdef HAVE_FREERDP_ADDIN_H
|
|
|
|
#include <freerdp/addin.h>
|
|
|
|
#endif
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2014-01-01 22:44:28 +00:00
|
|
|
#ifdef HAVE_FREERDP_CLIENT_CHANNELS_H
|
|
|
|
#include <freerdp/client/channels.h>
|
|
|
|
#endif
|
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",
|
2013-06-28 16:01:19 +00:00
|
|
|
"enable-printing",
|
2013-07-25 19:05:15 +00:00
|
|
|
"enable-drive",
|
2013-07-29 18:53:15 +00:00
|
|
|
"drive-path",
|
2012-12-26 03:36:19 +00:00
|
|
|
"console",
|
|
|
|
"console-audio",
|
2013-03-29 20:34:45 +00:00
|
|
|
"server-layout",
|
2013-08-24 19:30:38 +00:00
|
|
|
"security",
|
|
|
|
"ignore-cert",
|
2013-08-25 18:35:31 +00:00
|
|
|
"disable-auth",
|
2014-01-29 23:58:04 +00:00
|
|
|
"remote-app-name",
|
|
|
|
"remote-app-command",
|
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,
|
2013-06-28 16:01:19 +00:00
|
|
|
IDX_ENABLE_PRINTING,
|
2013-07-25 19:05:15 +00:00
|
|
|
IDX_ENABLE_DRIVE,
|
2013-07-29 18:53:15 +00:00
|
|
|
IDX_DRIVE_PATH,
|
2012-12-26 03:36:19 +00:00
|
|
|
IDX_CONSOLE,
|
2013-01-16 04:57:45 +00:00
|
|
|
IDX_CONSOLE_AUDIO,
|
2013-03-29 20:34:45 +00:00
|
|
|
IDX_SERVER_LAYOUT,
|
2013-08-24 19:30:38 +00:00
|
|
|
IDX_SECURITY,
|
2013-08-24 08:17:27 +00:00
|
|
|
IDX_IGNORE_CERT,
|
2013-08-25 18:35:31 +00:00
|
|
|
IDX_DISABLE_AUTH,
|
2014-01-29 23:58:04 +00:00
|
|
|
IDX_REMOTE_APP_NAME,
|
|
|
|
IDX_REMOTE_APP_COMMAND,
|
2013-01-16 04:57:45 +00:00
|
|
|
RDP_ARGS_COUNT
|
2012-02-23 19:27:23 +00:00
|
|
|
};
|
|
|
|
|
2013-07-17 18:54:24 +00:00
|
|
|
int __guac_receive_channel_data(freerdp* rdp_inst, int channelId, UINT8* data, int size, int flags, int total_size) {
|
2012-03-30 18:26:52 +00:00
|
|
|
return freerdp_channels_data(rdp_inst, channelId, data, size, flags, total_size);
|
|
|
|
}
|
|
|
|
|
2013-07-17 18:54:24 +00:00
|
|
|
BOOL rdp_freerdp_pre_connect(freerdp* instance) {
|
2012-01-03 09:01:33 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
rdp_guac_client_data* guac_client_data =
|
|
|
|
(rdp_guac_client_data*) client->data;
|
2012-02-08 20:32:27 +00:00
|
|
|
|
2013-07-18 16:34:02 +00:00
|
|
|
#ifdef HAVE_FREERDP_REGISTER_ADDIN_PROVIDER
|
2013-07-17 17:58:00 +00:00
|
|
|
/* Init FreeRDP add-in provider */
|
|
|
|
freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0);
|
2013-07-18 16:34:02 +00:00
|
|
|
#endif
|
2013-07-17 17:58:00 +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 */
|
2013-07-18 00:54:28 +00:00
|
|
|
if (guac_client_data->settings.audio_enabled) {
|
2012-10-28 07:23:44 +00:00
|
|
|
|
2013-09-24 19:01:02 +00:00
|
|
|
guac_client_data->audio = guac_audio_stream_alloc(client, NULL);
|
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,
|
2013-07-17 17:48:41 +00:00
|
|
|
"guacsnd", guac_client_data->audio))
|
2012-11-23 03:07:03 +00:00
|
|
|
guac_client_log_error(client,
|
2013-07-17 17:48:41 +00:00
|
|
|
"Failed to load guacsnd 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
|
|
|
|
2013-11-04 08:50:10 +00:00
|
|
|
/* Load filesystem if drive enabled */
|
|
|
|
if (guac_client_data->settings.drive_enabled) {
|
|
|
|
guac_client_data->filesystem =
|
|
|
|
guac_rdp_fs_alloc(guac_client_data->settings.drive_path);
|
|
|
|
}
|
|
|
|
|
2013-07-25 19:05:15 +00:00
|
|
|
/* If RDPDR required, load it */
|
|
|
|
if (guac_client_data->settings.printing_enabled
|
|
|
|
|| guac_client_data->settings.drive_enabled) {
|
2013-06-18 20:39:07 +00:00
|
|
|
|
|
|
|
/* Load RDPDR plugin */
|
|
|
|
if (freerdp_channels_load_plugin(channels, instance->settings,
|
2013-07-19 00:10:04 +00:00
|
|
|
"guacdr", client))
|
2013-06-18 20:39:07 +00:00
|
|
|
guac_client_log_error(client,
|
2013-07-19 00:10:04 +00:00
|
|
|
"Failed to load guacdr plugin.");
|
2013-06-18 20:39:07 +00:00
|
|
|
|
2013-07-25 19:05:15 +00:00
|
|
|
}
|
2013-06-18 20:39:07 +00:00
|
|
|
|
2014-01-30 00:25:30 +00:00
|
|
|
/* Load RAIL plugin if RemoteApp in use */
|
|
|
|
if (guac_client_data->settings.remote_app_name != NULL
|
|
|
|
|| guac_client_data->settings.remote_app_command != NULL) {
|
|
|
|
|
|
|
|
#ifdef LEGACY_FREERDP
|
|
|
|
RDP_PLUGIN_DATA* plugin_data = malloc(sizeof(RDP_PLUGIN_DATA) * 2);
|
|
|
|
|
|
|
|
plugin_data[0].size = sizeof(RDP_PLUGIN_DATA);
|
|
|
|
plugin_data[0].data[0] = guac_client_data->settings.remote_app_name;
|
|
|
|
plugin_data[0].data[1] = guac_client_data->settings.remote_app_command;
|
|
|
|
plugin_data[0].data[2] = NULL;
|
|
|
|
plugin_data[0].data[3] = NULL;
|
|
|
|
|
|
|
|
plugin_data[1].size = 0;
|
|
|
|
|
|
|
|
/* Attempt to load rail */
|
|
|
|
if (freerdp_channels_load_plugin(channels, instance->settings,
|
|
|
|
"rail", plugin_data))
|
|
|
|
guac_client_log_error(client, "Failed to load rail plugin.");
|
|
|
|
#else
|
|
|
|
/* Attempt to load rail */
|
|
|
|
if (freerdp_channels_load_plugin(channels, instance->settings,
|
|
|
|
"rail", instance->settings))
|
|
|
|
guac_client_log_error(client, "Failed to load rail plugin.");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-02-08 20:32:27 +00:00
|
|
|
/* Init color conversion structure */
|
2013-07-17 02:04:38 +00:00
|
|
|
clrconv = calloc(1, sizeof(CLRCONV));
|
2012-02-08 20:32:27 +00:00
|
|
|
clrconv->alpha = 1;
|
|
|
|
clrconv->invert = 0;
|
|
|
|
clrconv->rgb555 = 0;
|
2013-07-17 02:04:38 +00:00
|
|
|
clrconv->palette = calloc(1, sizeof(rdpPalette));
|
2012-02-08 20:32:27 +00:00
|
|
|
((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 */
|
2013-07-17 02:04:38 +00:00
|
|
|
bitmap = calloc(1, sizeof(rdpBitmap));
|
2012-01-03 09:01:33 +00:00
|
|
|
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);
|
2013-07-17 01:59:26 +00:00
|
|
|
free(bitmap);
|
2012-01-03 09:01:33 +00:00
|
|
|
|
2012-01-03 21:39:59 +00:00
|
|
|
/* Set up glyph handling */
|
2013-07-17 02:04:38 +00:00
|
|
|
glyph = calloc(1, sizeof(rdpGlyph));
|
2012-01-03 21:39:59 +00:00
|
|
|
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);
|
2013-07-17 01:59:26 +00:00
|
|
|
free(glyph);
|
2012-01-03 21:39:59 +00:00
|
|
|
|
|
|
|
/* Set up pointer handling */
|
2013-07-17 02:04:38 +00:00
|
|
|
pointer = calloc(1, sizeof(rdpPointer));
|
2012-01-03 21:39:59 +00:00
|
|
|
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);
|
2013-07-17 01:59:26 +00:00
|
|
|
free(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)) {
|
2013-09-28 02:26:37 +00:00
|
|
|
guac_protocol_send_error(client->socket,
|
|
|
|
"Error initializing RDP client channel manager",
|
|
|
|
GUAC_PROTOCOL_STATUS_INTERNAL_ERROR);
|
2012-01-03 09:01:33 +00:00
|
|
|
guac_socket_flush(client->socket);
|
2013-07-17 18:54:24 +00:00
|
|
|
return FALSE;
|
2012-01-03 09:01:33 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 18:54:24 +00:00
|
|
|
return TRUE;
|
2012-01-03 09:01:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-17 18:54:24 +00:00
|
|
|
BOOL rdp_freerdp_post_connect(freerdp* instance) {
|
2012-01-03 09:01:33 +00:00
|
|
|
|
|
|
|
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)) {
|
2013-09-28 02:26:37 +00:00
|
|
|
guac_protocol_send_error(client->socket,
|
|
|
|
"Error initializing RDP client channel manager",
|
|
|
|
GUAC_PROTOCOL_STATUS_INTERNAL_ERROR);
|
2012-01-03 09:01:33 +00:00
|
|
|
guac_socket_flush(client->socket);
|
2013-07-17 18:54:24 +00:00
|
|
|
return FALSE;
|
2012-01-03 09:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
2013-10-15 21:13:56 +00:00
|
|
|
/* File transfer handlers */
|
|
|
|
client->file_handler = rdp_guac_client_file_handler;
|
|
|
|
client->blob_handler = rdp_guac_client_blob_handler;
|
|
|
|
client->end_handler = rdp_guac_client_end_handler;
|
2013-11-12 19:46:32 +00:00
|
|
|
client->ack_handler = rdp_guac_client_ack_handler;
|
2013-10-15 21:13:56 +00:00
|
|
|
|
2013-07-17 18:54:24 +00:00
|
|
|
return TRUE;
|
2012-01-03 09:01:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-08-25 18:35:31 +00:00
|
|
|
BOOL rdp_freerdp_authenticate(freerdp* instance, char** username,
|
|
|
|
char** password, char** domain) {
|
|
|
|
|
|
|
|
rdpContext* context = instance->context;
|
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
|
|
|
|
|
|
|
/* Warn if connection is likely to fail due to lack of credentials */
|
|
|
|
guac_client_log_info(client,
|
|
|
|
"Authentication requested but username or password not given");
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL rdp_freerdp_verify_certificate(freerdp* instance, char* subject,
|
|
|
|
char* issuer, char* fingerprint) {
|
|
|
|
|
|
|
|
rdpContext* context = instance->context;
|
|
|
|
guac_client* client = ((rdp_freerdp_context*) context)->client;
|
|
|
|
rdp_guac_client_data* guac_client_data =
|
|
|
|
(rdp_guac_client_data*) client->data;
|
|
|
|
|
|
|
|
/* Bypass validation if ignore_certificate given */
|
|
|
|
if (guac_client_data->settings.ignore_certificate) {
|
|
|
|
guac_client_log_info(client, "Certificate validation bypassed");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
guac_client_log_info(client, "Certificate validation failed");
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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;
|
2013-07-18 00:54:28 +00:00
|
|
|
guac_rdp_settings* settings;
|
2011-12-30 08:10:28 +00:00
|
|
|
|
|
|
|
freerdp* rdp_inst;
|
|
|
|
|
2013-07-18 00:54:28 +00:00
|
|
|
/* Validate number of arguments received */
|
|
|
|
if (argc != RDP_ARGS_COUNT) {
|
2012-03-25 20:07:31 +00:00
|
|
|
|
|
|
|
guac_protocol_send_error(client->socket,
|
2013-09-28 02:26:37 +00:00
|
|
|
"Wrong argument count received.",
|
|
|
|
GUAC_PROTOCOL_STATUS_INVALID_PARAMETER);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate client data */
|
|
|
|
guac_client_data = malloc(sizeof(rdp_guac_client_data));
|
|
|
|
|
2013-06-21 22:47:08 +00:00
|
|
|
/* Init random number generator */
|
|
|
|
srandom(time(NULL));
|
|
|
|
|
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;
|
2013-08-25 18:35:31 +00:00
|
|
|
rdp_inst->Authenticate = rdp_freerdp_authenticate;
|
|
|
|
rdp_inst->VerifyCertificate = rdp_freerdp_verify_certificate;
|
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 */
|
2013-07-18 18:35:40 +00:00
|
|
|
#ifdef LEGACY_FREERDP
|
2012-01-03 09:01:33 +00:00
|
|
|
rdp_inst->context_size = sizeof(rdp_freerdp_context);
|
2013-07-18 18:35:40 +00:00
|
|
|
#else
|
|
|
|
rdp_inst->ContextSize = sizeof(rdp_freerdp_context);
|
|
|
|
#endif
|
2012-01-03 09:01:33 +00:00
|
|
|
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 */
|
2013-07-18 00:54:28 +00:00
|
|
|
settings = &(guac_client_data->settings);
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2012-12-26 03:36:19 +00:00
|
|
|
/* Console */
|
2013-07-18 00:54:28 +00:00
|
|
|
settings->console = (strcmp(argv[IDX_CONSOLE], "true") == 0);
|
2013-07-17 19:49:28 +00:00
|
|
|
settings->console_audio = (strcmp(argv[IDX_CONSOLE_AUDIO], "true") == 0);
|
2012-12-26 03:36:19 +00:00
|
|
|
|
2013-08-24 19:37:43 +00:00
|
|
|
/* Certificate and auth */
|
2013-08-24 08:17:27 +00:00
|
|
|
settings->ignore_certificate = (strcmp(argv[IDX_IGNORE_CERT], "true") == 0);
|
2013-08-25 18:35:31 +00:00
|
|
|
settings->disable_authentication = (strcmp(argv[IDX_DISABLE_AUTH], "true") == 0);
|
2013-08-24 08:17:27 +00:00
|
|
|
|
2013-08-24 19:37:43 +00:00
|
|
|
/* NLA security */
|
|
|
|
if (strcmp(argv[IDX_SECURITY], "nla") == 0) {
|
|
|
|
guac_client_log_info(client, "Security mode: NLA");
|
2013-08-24 19:30:38 +00:00
|
|
|
settings->security_mode = GUAC_SECURITY_NLA;
|
2013-08-24 19:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* TLS security */
|
|
|
|
else if (strcmp(argv[IDX_SECURITY], "tls") == 0) {
|
|
|
|
guac_client_log_info(client, "Security mode: TLS");
|
2013-08-24 19:30:38 +00:00
|
|
|
settings->security_mode = GUAC_SECURITY_TLS;
|
2013-08-24 19:37:43 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 18:35:31 +00:00
|
|
|
/* RDP security */
|
|
|
|
else if (strcmp(argv[IDX_SECURITY], "rdp") == 0) {
|
|
|
|
guac_client_log_info(client, "Security mode: RDP");
|
|
|
|
settings->security_mode = GUAC_SECURITY_RDP;
|
2013-08-24 19:37:43 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 18:35:31 +00:00
|
|
|
/* ANY security (allow server to choose) */
|
2013-08-27 04:26:38 +00:00
|
|
|
else if (strcmp(argv[IDX_SECURITY], "any") == 0) {
|
2013-08-25 18:35:31 +00:00
|
|
|
guac_client_log_info(client, "Security mode: ANY");
|
|
|
|
settings->security_mode = GUAC_SECURITY_ANY;
|
2013-08-24 19:37:43 +00:00
|
|
|
}
|
2013-08-24 19:30:38 +00:00
|
|
|
|
2013-08-27 04:26:38 +00:00
|
|
|
/* If nothing given, default to RDP */
|
|
|
|
else {
|
|
|
|
guac_client_log_info(client, "No security mode specified. Defaulting to RDP.");
|
|
|
|
settings->security_mode = GUAC_SECURITY_RDP;
|
|
|
|
}
|
|
|
|
|
2013-07-18 00:54:28 +00:00
|
|
|
/* Set hostname */
|
|
|
|
settings->hostname = strdup(argv[IDX_HOSTNAME]);
|
2012-01-03 09:05:21 +00:00
|
|
|
|
2013-07-18 00:54:28 +00:00
|
|
|
/* If port specified, use it */
|
|
|
|
settings->port = RDP_DEFAULT_PORT;
|
|
|
|
if (argv[IDX_PORT][0] != '\0')
|
|
|
|
settings->port = atoi(argv[IDX_PORT]);
|
2012-01-03 09:05:21 +00:00
|
|
|
|
2012-10-22 22:02:58 +00:00
|
|
|
/* Use optimal width unless overridden */
|
2013-12-27 08:34:37 +00:00
|
|
|
settings->width = client->info.optimal_width * 96 / client->info.optimal_resolution;
|
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-09-03 21:09:33 +00:00
|
|
|
/* Round width down to nearest multiple of 4 */
|
|
|
|
settings->width = settings->width & ~0x3;
|
2013-01-23 09:34:51 +00:00
|
|
|
|
2012-10-22 22:02:58 +00:00
|
|
|
/* Use optimal height unless overridden */
|
2013-12-27 08:34:37 +00:00
|
|
|
settings->height = client->info.optimal_height * 96 / client->info.optimal_resolution;
|
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-05-04 08:11:07 +00:00
|
|
|
/* Domain */
|
2013-07-18 00:54:28 +00:00
|
|
|
settings->domain = NULL;
|
2012-05-04 08:11:07 +00:00
|
|
|
if (argv[IDX_DOMAIN][0] != '\0')
|
|
|
|
settings->domain = strdup(argv[IDX_DOMAIN]);
|
|
|
|
|
|
|
|
/* Username */
|
2013-07-18 00:54:28 +00:00
|
|
|
settings->username = NULL;
|
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 */
|
2013-07-18 00:54:28 +00:00
|
|
|
settings->password = NULL;
|
|
|
|
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
|
|
|
|
2012-05-04 08:11:07 +00:00
|
|
|
/* Initial program */
|
2013-07-18 00:54:28 +00:00
|
|
|
settings->initial_program = NULL;
|
2012-02-27 18:36:14 +00:00
|
|
|
if (argv[IDX_INITIAL_PROGRAM][0] != '\0')
|
2013-07-18 00:54:28 +00:00
|
|
|
settings->initial_program = strdup(argv[IDX_INITIAL_PROGRAM]);
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2014-01-29 23:58:04 +00:00
|
|
|
/* RemoteApp name */
|
|
|
|
settings->remote_app_name = NULL;
|
|
|
|
if (argv[IDX_REMOTE_APP_NAME][0] != '\0')
|
|
|
|
settings->remote_app_name = strdup(argv[IDX_REMOTE_APP_NAME]);
|
|
|
|
|
|
|
|
/* RemoteApp command */
|
|
|
|
settings->remote_app_command = NULL;
|
|
|
|
if (argv[IDX_REMOTE_APP_COMMAND][0] != '\0')
|
|
|
|
settings->remote_app_command = strdup(argv[IDX_REMOTE_APP_COMMAND]);
|
|
|
|
|
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 */
|
2013-07-18 00:54:28 +00:00
|
|
|
guac_client_data->settings.audio_enabled =
|
2013-07-17 19:49:28 +00:00
|
|
|
(strcmp(argv[IDX_DISABLE_AUDIO], "true") != 0);
|
2012-11-23 03:07:03 +00:00
|
|
|
|
2013-06-18 20:39:07 +00:00
|
|
|
/* Printing enable/disable */
|
2013-07-18 00:54:28 +00:00
|
|
|
guac_client_data->settings.printing_enabled =
|
2013-07-17 19:49:28 +00:00
|
|
|
(strcmp(argv[IDX_ENABLE_PRINTING], "true") == 0);
|
2013-06-18 20:39:07 +00:00
|
|
|
|
2013-07-25 19:05:15 +00:00
|
|
|
/* Drive enable/disable */
|
|
|
|
guac_client_data->settings.drive_enabled =
|
|
|
|
(strcmp(argv[IDX_ENABLE_DRIVE], "true") == 0);
|
|
|
|
|
2013-07-29 18:53:15 +00:00
|
|
|
guac_client_data->settings.drive_path = strdup(argv[IDX_DRIVE_PATH]);
|
|
|
|
|
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;
|
2013-07-17 18:54:24 +00:00
|
|
|
guac_client_data->bounded = FALSE;
|
2011-12-30 08:10:28 +00:00
|
|
|
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;
|
2013-11-04 08:50:10 +00:00
|
|
|
guac_client_data->filesystem = NULL;
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2013-06-29 00:45:47 +00:00
|
|
|
/* Main socket needs to be threadsafe */
|
|
|
|
guac_socket_require_threadsafe(client->socket);
|
|
|
|
|
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 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 */
|
2014-01-03 07:41:16 +00:00
|
|
|
settings->server_layout = NULL;
|
|
|
|
if (argv[IDX_SERVER_LAYOUT][0] != '\0')
|
|
|
|
settings->server_layout =
|
|
|
|
guac_rdp_keymap_find(argv[IDX_SERVER_LAYOUT]);
|
|
|
|
|
|
|
|
/* If no keymap requested, use default */
|
2014-01-03 09:31:09 +00:00
|
|
|
if (settings->server_layout == NULL)
|
2014-01-03 07:41:16 +00:00
|
|
|
settings->server_layout = guac_rdp_keymap_find(GUAC_DEFAULT_KEYMAP);
|
2013-03-29 20:08:14 +00:00
|
|
|
|
2012-03-21 17:45:40 +00:00
|
|
|
/* Load keymap into client */
|
2013-07-18 00:54:28 +00:00
|
|
|
__guac_rdp_client_load_keymap(client, settings->server_layout);
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2013-07-20 01:37:05 +00:00
|
|
|
/* Push desired settings to FreeRDP */
|
|
|
|
guac_rdp_push_settings(settings, rdp_inst);
|
2013-07-19 00:26:07 +00:00
|
|
|
|
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,
|
2013-09-28 02:26:37 +00:00
|
|
|
"Error connecting to RDP server",
|
|
|
|
GUAC_PROTOCOL_STATUS_INTERNAL_ERROR);
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-20 01:37:05 +00:00
|
|
|
/* Pull actual settings back from FreeRDP */
|
|
|
|
guac_rdp_pull_settings(rdp_inst, settings);
|
|
|
|
|
2012-03-26 04:49:58 +00:00
|
|
|
/* Send connection name */
|
2013-07-18 00:54:28 +00:00
|
|
|
guac_protocol_send_name(client->socket, settings->hostname);
|
2012-03-26 04:49:58 +00:00
|
|
|
|
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 */
|
2014-01-07 00:21:23 +00:00
|
|
|
guac_common_set_pointer_cursor(client);
|
2012-05-17 02:52:43 +00:00
|
|
|
|
2011-12-30 08:10:28 +00:00
|
|
|
/* Success */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-19 19:21:34 +00:00
|
|
|
int guac_rdp_clip_rect(rdp_guac_client_data* data, int* x, int* y, int* w, int* h) {
|
2013-06-15 05:16:25 +00:00
|
|
|
|
|
|
|
if (data->bounded) {
|
|
|
|
|
|
|
|
/* Get rect coordinates */
|
|
|
|
int clipped_left = *x;
|
|
|
|
int clipped_top = *y;
|
|
|
|
int clipped_right = clipped_left + *w - 1;
|
|
|
|
int clipped_bottom = clipped_top + *h - 1;
|
|
|
|
|
|
|
|
/* Clip left */
|
|
|
|
if (clipped_left < data->bounds_left) clipped_left = data->bounds_left;
|
2013-07-19 19:21:34 +00:00
|
|
|
else if (clipped_left > data->bounds_right) return 1;
|
2013-06-15 05:16:25 +00:00
|
|
|
|
|
|
|
/* Clip right */
|
2013-07-19 19:21:34 +00:00
|
|
|
if (clipped_right < data->bounds_left) return 1;
|
2013-06-15 05:16:25 +00:00
|
|
|
else if (clipped_right > data->bounds_right) clipped_right = data->bounds_right;
|
|
|
|
|
|
|
|
/* Clip top */
|
|
|
|
if (clipped_top < data->bounds_top) clipped_top = data->bounds_top;
|
2013-07-19 19:21:34 +00:00
|
|
|
else if (clipped_top > data->bounds_bottom) return 1;
|
2013-06-15 05:16:25 +00:00
|
|
|
|
|
|
|
/* Clip bottom */
|
2013-07-19 19:21:34 +00:00
|
|
|
if (clipped_bottom < data->bounds_top) return 1;
|
2013-06-15 05:16:25 +00:00
|
|
|
else if (clipped_bottom > data->bounds_bottom) clipped_bottom = data->bounds_bottom;
|
|
|
|
|
|
|
|
/* Store new rect dimensions */
|
|
|
|
*x = clipped_left;
|
|
|
|
*y = clipped_top;
|
|
|
|
*w = clipped_right - clipped_left + 1;
|
|
|
|
*h = clipped_bottom - clipped_top + 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-19 19:21:34 +00:00
|
|
|
return 0;
|
|
|
|
|
2013-06-15 05:16:25 +00:00
|
|
|
}
|
|
|
|
|