2013-06-18 20:39:07 +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 ***** */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <freerdp/constants.h>
|
|
|
|
#include <freerdp/utils/svc_plugin.h>
|
|
|
|
|
2013-07-17 18:45:53 +00:00
|
|
|
#ifdef ENABLE_WINPR
|
|
|
|
#include <winpr/stream.h>
|
|
|
|
#include <winpr/wtypes.h>
|
|
|
|
#else
|
|
|
|
#include "compat/winpr-stream.h"
|
|
|
|
#include "compat/winpr-wtypes.h"
|
|
|
|
#endif
|
|
|
|
|
2013-06-18 20:39:07 +00:00
|
|
|
#include <guacamole/client.h>
|
|
|
|
|
|
|
|
#include "rdpdr_service.h"
|
|
|
|
#include "rdpdr_messages.h"
|
2013-07-25 05:20:29 +00:00
|
|
|
#include "rdpdr_printer.h"
|
2013-07-25 16:48:48 +00:00
|
|
|
#include "rdpdr_fs.h"
|
2013-06-18 20:39:07 +00:00
|
|
|
|
2013-07-25 05:49:24 +00:00
|
|
|
#include "client.h"
|
|
|
|
|
2013-06-18 20:39:07 +00:00
|
|
|
|
2013-07-17 18:45:53 +00:00
|
|
|
/**
|
|
|
|
* Entry point for RDPDR virtual channel.
|
|
|
|
*/
|
|
|
|
int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) {
|
|
|
|
|
|
|
|
/* Allocate plugin */
|
|
|
|
guac_rdpdrPlugin* rdpdr =
|
|
|
|
(guac_rdpdrPlugin*) calloc(1, sizeof(guac_rdpdrPlugin));
|
|
|
|
|
|
|
|
/* Init channel def */
|
2013-07-20 00:56:55 +00:00
|
|
|
strcpy(rdpdr->plugin.channel_def.name, "rdpdr");
|
2013-07-17 18:45:53 +00:00
|
|
|
rdpdr->plugin.channel_def.options =
|
|
|
|
CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP | CHANNEL_OPTION_COMPRESS_RDP;
|
|
|
|
|
|
|
|
/* Set callbacks */
|
|
|
|
rdpdr->plugin.connect_callback = guac_rdpdr_process_connect;
|
|
|
|
rdpdr->plugin.receive_callback = guac_rdpdr_process_receive;
|
|
|
|
rdpdr->plugin.event_callback = guac_rdpdr_process_event;
|
|
|
|
rdpdr->plugin.terminate_callback = guac_rdpdr_process_terminate;
|
2013-06-18 20:39:07 +00:00
|
|
|
|
2013-07-17 18:45:53 +00:00
|
|
|
/* Finish init */
|
|
|
|
svc_plugin_init((rdpSvcPlugin*) rdpdr, pEntryPoints);
|
|
|
|
return 1;
|
2013-06-18 20:39:07 +00:00
|
|
|
|
2013-07-17 18:45:53 +00:00
|
|
|
}
|
2013-06-18 20:39:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Service Handlers
|
|
|
|
*/
|
|
|
|
|
|
|
|
void guac_rdpdr_process_connect(rdpSvcPlugin* plugin) {
|
|
|
|
|
2013-06-18 21:02:38 +00:00
|
|
|
/* Get RDPDR plugin */
|
|
|
|
guac_rdpdrPlugin* rdpdr = (guac_rdpdrPlugin*) plugin;
|
|
|
|
|
2013-08-22 21:51:37 +00:00
|
|
|
/* Get client from plugin parameters */
|
2013-06-18 21:02:38 +00:00
|
|
|
guac_client* client = (guac_client*)
|
|
|
|
plugin->channel_entry_points.pExtendedData;
|
|
|
|
|
2013-08-22 21:51:37 +00:00
|
|
|
/* NULL out pExtendedData so we don't lose our guac_client due to an
|
|
|
|
* automatic free() within libfreerdp */
|
|
|
|
plugin->channel_entry_points.pExtendedData = NULL;
|
|
|
|
|
2013-07-25 05:49:24 +00:00
|
|
|
/* Get data from client */
|
|
|
|
rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;
|
|
|
|
|
2013-06-18 21:02:38 +00:00
|
|
|
/* Init plugin */
|
|
|
|
rdpdr->client = client;
|
2013-07-25 06:51:49 +00:00
|
|
|
rdpdr->devices_registered = 0;
|
2013-06-18 21:02:38 +00:00
|
|
|
|
2013-07-25 05:49:24 +00:00
|
|
|
/* Register printer if enabled */
|
|
|
|
if (client_data->settings.printing_enabled)
|
|
|
|
guac_rdpdr_register_printer(rdpdr);
|
2013-07-25 01:28:20 +00:00
|
|
|
|
2013-07-25 16:48:48 +00:00
|
|
|
guac_rdpdr_register_fs(rdpdr);
|
|
|
|
|
2013-06-18 21:02:38 +00:00
|
|
|
/* Log that printing, etc. has been loaded */
|
2013-07-17 18:45:53 +00:00
|
|
|
guac_client_log_info(client, "guacdr connected.");
|
2013-06-18 20:39:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void guac_rdpdr_process_terminate(rdpSvcPlugin* plugin) {
|
2013-07-25 05:49:24 +00:00
|
|
|
|
|
|
|
guac_rdpdrPlugin* rdpdr = (guac_rdpdrPlugin*) plugin;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<rdpdr->devices_registered; i++) {
|
|
|
|
guac_rdpdr_device* device = &(rdpdr->devices[i]);
|
|
|
|
guac_client_log_info(rdpdr->client, "Unloading device %i (%s)",
|
|
|
|
device->device_id, device->device_name);
|
|
|
|
device->free_handler(device);
|
|
|
|
}
|
|
|
|
|
2013-07-17 01:59:26 +00:00
|
|
|
free(plugin);
|
2013-06-18 20:39:07 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 18:45:53 +00:00
|
|
|
void guac_rdpdr_process_event(rdpSvcPlugin* plugin, wMessage* event) {
|
2013-06-18 20:39:07 +00:00
|
|
|
freerdp_event_free(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void guac_rdpdr_process_receive(rdpSvcPlugin* plugin,
|
2013-07-17 18:45:53 +00:00
|
|
|
wStream* input_stream) {
|
2013-06-18 20:39:07 +00:00
|
|
|
|
2013-06-18 21:02:38 +00:00
|
|
|
guac_rdpdrPlugin* rdpdr = (guac_rdpdrPlugin*) plugin;
|
2013-06-18 20:39:07 +00:00
|
|
|
|
2013-06-19 23:23:11 +00:00
|
|
|
int component;
|
|
|
|
int packet_id;
|
|
|
|
|
|
|
|
/* Read header */
|
2013-07-17 18:45:53 +00:00
|
|
|
Stream_Read_UINT16(input_stream, component);
|
|
|
|
Stream_Read_UINT16(input_stream, packet_id);
|
2013-06-19 23:23:11 +00:00
|
|
|
|
|
|
|
/* Core component */
|
|
|
|
if (component == RDPDR_CTYP_CORE) {
|
|
|
|
|
|
|
|
/* Dispatch handlers based on packet ID */
|
|
|
|
switch (packet_id) {
|
|
|
|
|
|
|
|
case PAKID_CORE_SERVER_ANNOUNCE:
|
2013-06-19 23:26:30 +00:00
|
|
|
guac_rdpdr_process_server_announce(rdpdr, input_stream);
|
2013-06-19 23:23:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAKID_CORE_CLIENTID_CONFIRM:
|
2013-06-20 23:04:59 +00:00
|
|
|
guac_rdpdr_process_clientid_confirm(rdpdr, input_stream);
|
2013-06-19 23:23:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAKID_CORE_DEVICE_REPLY:
|
2013-06-20 23:04:59 +00:00
|
|
|
guac_rdpdr_process_device_reply(rdpdr, input_stream);
|
2013-06-19 23:23:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAKID_CORE_DEVICE_IOREQUEST:
|
2013-06-20 23:04:59 +00:00
|
|
|
guac_rdpdr_process_device_iorequest(rdpdr, input_stream);
|
2013-06-19 23:23:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAKID_CORE_SERVER_CAPABILITY:
|
2013-06-20 23:04:59 +00:00
|
|
|
guac_rdpdr_process_server_capability(rdpdr, input_stream);
|
2013-06-19 23:23:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAKID_CORE_USER_LOGGEDON:
|
2013-06-20 23:04:59 +00:00
|
|
|
guac_rdpdr_process_user_loggedon(rdpdr, input_stream);
|
2013-06-19 23:23:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
guac_client_log_info(rdpdr->client, "Ignoring RDPDR core packet with unexpected ID: 0x%04x", packet_id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* end if core */
|
|
|
|
|
|
|
|
/* Printer component */
|
|
|
|
else if (component == RDPDR_CTYP_PRN) {
|
|
|
|
|
|
|
|
/* Dispatch handlers based on packet ID */
|
|
|
|
switch (packet_id) {
|
|
|
|
|
|
|
|
case PAKID_PRN_CACHE_DATA:
|
2013-06-20 23:04:59 +00:00
|
|
|
guac_rdpdr_process_prn_cache_data(rdpdr, input_stream);
|
2013-06-19 23:23:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAKID_PRN_USING_XPS:
|
2013-06-20 23:04:59 +00:00
|
|
|
guac_rdpdr_process_prn_using_xps(rdpdr, input_stream);
|
2013-06-19 23:23:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
guac_client_log_info(rdpdr->client, "Ignoring RDPDR printer packet with unexpected ID: 0x%04x", packet_id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* end if printer */
|
|
|
|
|
|
|
|
else
|
|
|
|
guac_client_log_info(rdpdr->client, "Ignoring packet for unknown RDPDR component: 0x%04x", component);
|
2013-06-18 20:39:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|