2011-03-26 04:58:46 +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):
|
|
|
|
*
|
|
|
|
* 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 ***** */
|
|
|
|
|
2011-03-26 05:49:48 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-03-28 02:04:05 +00:00
|
|
|
#include <sys/select.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2011-03-26 05:49:48 +00:00
|
|
|
#include <freerdp/freerdp.h>
|
2011-12-30 08:10:28 +00:00
|
|
|
#include <freerdp/channels/channels.h>
|
|
|
|
#include <freerdp/input.h>
|
2011-03-26 04:58:46 +00:00
|
|
|
|
2011-11-26 23:47:11 +00:00
|
|
|
#include <guacamole/socket.h>
|
2011-03-26 04:58:46 +00:00
|
|
|
#include <guacamole/protocol.h>
|
|
|
|
#include <guacamole/client.h>
|
|
|
|
|
2011-12-30 08:10:28 +00:00
|
|
|
#include "client.h"
|
2011-07-24 07:47:38 +00:00
|
|
|
#include "rdp_keymap.h"
|
2012-01-03 08:24:03 +00:00
|
|
|
#include "guac_handlers.h"
|
2011-03-26 05:49:48 +00:00
|
|
|
|
2011-03-26 05:59:39 +00:00
|
|
|
int rdp_guac_client_free_handler(guac_client* client) {
|
|
|
|
|
2012-01-03 08:24:03 +00:00
|
|
|
/* STUB */
|
2011-03-26 05:59:39 +00:00
|
|
|
|
2012-01-03 08:24:03 +00:00
|
|
|
/* FIXME: Clean up RDP client + disconnect */
|
2011-03-26 05:59:39 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-03-28 02:04:05 +00:00
|
|
|
int rdp_guac_client_handle_messages(guac_client* client) {
|
|
|
|
|
|
|
|
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
|
2012-01-03 08:24:03 +00:00
|
|
|
freerdp* rdp_inst = guac_client_data->rdp_inst;
|
2011-12-30 08:10:28 +00:00
|
|
|
rdpChannels* channels = guac_client_data->channels;
|
2011-03-28 02:04:05 +00:00
|
|
|
|
|
|
|
int index;
|
|
|
|
int max_fd, fd;
|
|
|
|
void* read_fds[32];
|
|
|
|
void* write_fds[32];
|
|
|
|
int read_count = 0;
|
|
|
|
int write_count = 0;
|
|
|
|
|
|
|
|
fd_set rfds, wfds;
|
|
|
|
|
|
|
|
/* get rdp fds */
|
2012-01-03 08:24:03 +00:00
|
|
|
if (freerdp_get_fds(rdp_inst, read_fds, &read_count, write_fds, &write_count) != 0) {
|
2011-11-26 23:47:11 +00:00
|
|
|
guac_client_log_error(client, "Unable to read RDP file descriptors.");
|
2011-03-28 02:04:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get channel fds */
|
2011-12-30 08:10:28 +00:00
|
|
|
if (freerdp_channels_get_fds(channels, rdp_inst, read_fds, &read_count, write_fds, &write_count) != 0) {
|
2011-11-26 23:47:11 +00:00
|
|
|
guac_client_log_error(client, "Unable to read RDP channel file descriptors.");
|
2011-03-28 02:04:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Construct read fd_set */
|
|
|
|
max_fd = 0;
|
|
|
|
FD_ZERO(&rfds);
|
|
|
|
for (index = 0; index < read_count; index++) {
|
|
|
|
fd = (int)(long) (read_fds[index]);
|
|
|
|
if (fd > max_fd)
|
|
|
|
max_fd = fd;
|
|
|
|
FD_SET(fd, &rfds);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Construct write fd_set */
|
|
|
|
FD_ZERO(&wfds);
|
|
|
|
for (index = 0; index < write_count; index++) {
|
|
|
|
fd = (int)(long) (write_fds[index]);
|
|
|
|
if (fd > max_fd)
|
|
|
|
max_fd = fd;
|
|
|
|
FD_SET(fd, &wfds);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If no file descriptors, error */
|
|
|
|
if (max_fd == 0) {
|
2011-11-26 23:47:11 +00:00
|
|
|
guac_client_log_error(client, "No file descriptors");
|
2011-03-28 02:04:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, wait for file descriptors given */
|
|
|
|
if (select(max_fd + 1, &rfds, &wfds, NULL, NULL) == -1) {
|
|
|
|
/* these are not really errors */
|
|
|
|
if (!((errno == EAGAIN) ||
|
|
|
|
(errno == EWOULDBLOCK) ||
|
|
|
|
(errno == EINPROGRESS) ||
|
|
|
|
(errno == EINTR))) /* signal occurred */
|
|
|
|
{
|
2011-11-26 23:47:11 +00:00
|
|
|
guac_client_log_error(client, "Error waiting for file descriptor.");
|
2011-03-28 02:04:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check the libfreerdp fds */
|
2012-01-03 08:24:03 +00:00
|
|
|
if (freerdp_check_fds(rdp_inst) != 0) {
|
2011-11-26 23:47:11 +00:00
|
|
|
guac_client_log_error(client, "Error handling RDP file descriptors.");
|
2011-03-28 02:04:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check channel fds */
|
2011-12-30 08:10:28 +00:00
|
|
|
if (freerdp_channels_check_fds(channels, rdp_inst) != 0) {
|
2011-11-26 23:47:11 +00:00
|
|
|
guac_client_log_error(client, "Error handling RDP channel file descriptors.");
|
2011-03-28 02:04:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Success */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-07-21 22:17:16 +00:00
|
|
|
int rdp_guac_client_mouse_handler(guac_client* client, int x, int y, int mask) {
|
|
|
|
|
|
|
|
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
|
2012-01-03 08:24:03 +00:00
|
|
|
freerdp* rdp_inst = guac_client_data->rdp_inst;
|
2011-07-21 22:17:16 +00:00
|
|
|
|
2011-07-25 21:57:40 +00:00
|
|
|
/* If button mask unchanged, just send move event */
|
|
|
|
if (mask == guac_client_data->mouse_button_mask)
|
2012-01-03 08:24:03 +00:00
|
|
|
rdp_inst->input->MouseEvent(rdp_inst->input, PTR_FLAGS_MOVE, x, y);
|
2011-07-21 22:17:16 +00:00
|
|
|
|
2011-07-25 21:57:40 +00:00
|
|
|
/* Otherwise, send events describing button change */
|
|
|
|
else {
|
2011-07-21 22:17:16 +00:00
|
|
|
|
2011-07-27 17:06:12 +00:00
|
|
|
/* Mouse buttons which have JUST become released */
|
|
|
|
int released_mask = guac_client_data->mouse_button_mask & ~mask;
|
|
|
|
|
|
|
|
/* Mouse buttons which have JUST become pressed */
|
|
|
|
int pressed_mask = ~guac_client_data->mouse_button_mask & mask;
|
|
|
|
|
2011-07-25 21:57:40 +00:00
|
|
|
/* Release event */
|
2011-07-27 17:06:12 +00:00
|
|
|
if (released_mask & 0x07) {
|
|
|
|
|
|
|
|
/* Calculate flags */
|
|
|
|
int flags = 0;
|
2011-12-30 08:10:28 +00:00
|
|
|
if (released_mask & 0x01) flags |= PTR_FLAGS_BUTTON1;
|
|
|
|
if (released_mask & 0x02) flags |= PTR_FLAGS_BUTTON3;
|
|
|
|
if (released_mask & 0x04) flags |= PTR_FLAGS_BUTTON2;
|
2011-07-27 17:06:12 +00:00
|
|
|
|
2012-01-03 08:24:03 +00:00
|
|
|
rdp_inst->input->MouseEvent(rdp_inst->input, flags, x, y);
|
2011-07-27 17:06:12 +00:00
|
|
|
|
|
|
|
}
|
2011-07-21 22:17:16 +00:00
|
|
|
|
2011-07-25 21:57:40 +00:00
|
|
|
/* Press event */
|
2011-07-27 17:06:12 +00:00
|
|
|
if (pressed_mask & 0x07) {
|
|
|
|
|
|
|
|
/* Calculate flags */
|
2011-12-30 08:10:28 +00:00
|
|
|
int flags = PTR_FLAGS_DOWN;
|
|
|
|
if (pressed_mask & 0x01) flags |= PTR_FLAGS_BUTTON1;
|
|
|
|
if (pressed_mask & 0x02) flags |= PTR_FLAGS_BUTTON3;
|
|
|
|
if (pressed_mask & 0x04) flags |= PTR_FLAGS_BUTTON2;
|
|
|
|
if (pressed_mask & 0x08) flags |= PTR_FLAGS_WHEEL | 0x78;
|
|
|
|
if (pressed_mask & 0x10) flags |= PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x88;
|
2011-07-27 17:06:12 +00:00
|
|
|
|
|
|
|
/* Send event */
|
2012-01-03 08:24:03 +00:00
|
|
|
rdp_inst->input->MouseEvent(rdp_inst->input, flags, x, y);
|
2011-07-27 17:06:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scroll event */
|
|
|
|
if (pressed_mask & 0x18) {
|
|
|
|
|
|
|
|
/* Down */
|
|
|
|
if (pressed_mask & 0x08)
|
2012-01-03 08:24:03 +00:00
|
|
|
rdp_inst->input->MouseEvent(
|
|
|
|
rdp_inst->input,
|
2011-12-30 08:10:28 +00:00
|
|
|
PTR_FLAGS_WHEEL | 0x78,
|
2011-07-27 17:06:12 +00:00
|
|
|
x, y);
|
|
|
|
|
|
|
|
/* Up */
|
|
|
|
if (pressed_mask & 0x10)
|
2012-01-03 08:24:03 +00:00
|
|
|
rdp_inst->input->MouseEvent(
|
|
|
|
rdp_inst->input,
|
2011-12-30 08:10:28 +00:00
|
|
|
PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x88,
|
2011-07-27 17:06:12 +00:00
|
|
|
x, y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-07-25 21:57:40 +00:00
|
|
|
|
|
|
|
guac_client_data->mouse_button_mask = mask;
|
|
|
|
}
|
2011-07-21 22:17:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-07-24 07:47:38 +00:00
|
|
|
|
|
|
|
int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
|
|
|
|
|
|
|
|
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
|
2012-01-03 08:24:03 +00:00
|
|
|
freerdp* rdp_inst = guac_client_data->rdp_inst;
|
2011-07-24 07:47:38 +00:00
|
|
|
|
|
|
|
/* If keysym can be in lookup table */
|
|
|
|
if (keysym <= 0xFFFF) {
|
|
|
|
|
|
|
|
/* Look up scancode */
|
2011-07-25 06:35:54 +00:00
|
|
|
const guac_rdp_keymap* keymap =
|
|
|
|
&guac_rdp_keysym_scancode[(keysym & 0xFF00) >> 8][keysym & 0xFF];
|
2011-07-24 07:47:38 +00:00
|
|
|
|
|
|
|
/* If defined, send event */
|
2011-07-25 06:35:54 +00:00
|
|
|
if (keymap->scancode != 0)
|
2012-01-03 08:24:03 +00:00
|
|
|
rdp_inst->input->KeyboardEvent(
|
|
|
|
rdp_inst->input,
|
|
|
|
keymap->flags
|
|
|
|
| (pressed ? KBD_FLAGS_DOWN : KBD_FLAGS_RELEASE),
|
2011-08-18 17:44:34 +00:00
|
|
|
keymap->scancode);
|
2011-07-26 03:16:56 +00:00
|
|
|
else
|
2011-11-26 23:47:11 +00:00
|
|
|
guac_client_log_info(client, "unmapped keysym: 0x%x", keysym);
|
2011-07-24 07:47:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|