guacamole-spice-protocol/protocols/rdp/src/rdp_client.c

245 lines
7.5 KiB
C
Raw Normal View History

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>
#include <freerdp/freerdp.h>
#include <freerdp/chanman.h>
2011-03-26 04:58:46 +00:00
#include <guacamole/log.h>
#include <guacamole/guacio.h>
#include <guacamole/protocol.h>
#include <guacamole/client.h>
2011-03-26 05:49:48 +00:00
#define RDP_DEFAULT_PORT 3389
2011-03-26 04:58:46 +00:00
/* Client plugin arguments */
const char* GUAC_CLIENT_ARGS[] = {
"hostname",
"port",
NULL
};
2011-03-26 05:59:39 +00:00
typedef struct rdp_guac_client_data {
rdpInst* rdp_inst;
rdpChanMan* chanman;
rdpSet* settings;
} rdp_guac_client_data;
int rdp_guac_client_free_handler(guac_client* client) {
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
2011-03-26 06:48:39 +00:00
/* Disconnect client */
guac_client_data->rdp_inst->rdp_disconnect(guac_client_data->rdp_inst);
2011-03-26 05:59:39 +00:00
/* Free RDP client */
freerdp_free(guac_client_data->rdp_inst);
freerdp_chanman_free(guac_client_data->chanman);
free(guac_client_data->settings);
/* Free guac client data */
free(guac_client_data);
return 0;
}
2011-03-27 02:14:39 +00:00
int guac_rdp_ui_select(rdpInst* inst, int socket) {
return 1;
}
2011-03-26 06:48:39 +00:00
void guac_rdp_ui_error(rdpInst* inst, char* text) {
guac_client* client = (guac_client*) inst->param1;
GUACIO* io = client->io;
guac_send_error(io, text);
guac_flush(io);
}
2011-03-26 04:58:46 +00:00
int guac_client_init(guac_client* client, int argc, char** argv) {
2011-03-26 05:59:39 +00:00
rdp_guac_client_data* guac_client_data;
2011-03-26 05:49:48 +00:00
rdpInst* rdp_inst;
rdpChanMan* chanman;
rdpSet* settings;
char* hostname;
int port = RDP_DEFAULT_PORT;
if (argc < 2) {
guac_send_error(client->io, "Wrong argument count received.");
guac_flush(client->io);
return 1;
}
/* If port specified, use it */
if (argv[1][0] != '\0')
port = atoi(argv[1]);
hostname = argv[0];
2011-03-26 06:48:39 +00:00
/* Allocate client data */
guac_client_data = malloc(sizeof(rdp_guac_client_data));
2011-03-26 05:49:48 +00:00
/* Get channel manager */
chanman = freerdp_chanman_new();
2011-03-26 06:48:39 +00:00
guac_client_data->chanman = chanman;
2011-03-26 05:49:48 +00:00
/* INIT SETTINGS */
settings = malloc(sizeof(rdpSet));
memset(settings, 0, sizeof(rdpSet));
2011-03-26 06:48:39 +00:00
guac_client_data->settings = settings;
2011-03-26 05:49:48 +00:00
/* Set hostname */
strncpy(settings->hostname, hostname, sizeof(settings->hostname) - 1);
/* Default size */
settings->width = 1024;
settings->height = 768;
strncpy(settings->server, hostname, sizeof(settings->server));
strcpy(settings->username, "guest");
settings->tcp_port_rdp = port;
settings->encryption = 1;
settings->server_depth = 16;
settings->bitmap_cache = 1;
settings->bitmap_compression = 1;
settings->desktop_save = 0;
settings->rdp5_performanceflags =
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
settings->off_screen_bitmaps = 1;
settings->triblt = 0;
settings->new_cursors = 1;
settings->rdp_version = 5;
/* Init client */
rdp_inst = freerdp_new(settings);
if (rdp_inst == NULL) {
guac_send_error(client->io, "Error initializing RDP client");
guac_flush(client->io);
return 1;
}
2011-03-26 06:48:39 +00:00
guac_client_data->rdp_inst = rdp_inst;
2011-03-26 05:49:48 +00:00
2011-03-26 06:48:39 +00:00
/* Store client data */
rdp_inst->param1 = client;
client->data = guac_client_data;
2011-03-26 05:49:48 +00:00
2011-03-26 06:48:39 +00:00
/* RDP handlers */
rdp_inst->ui_error = guac_rdp_ui_error;
2011-03-27 02:14:39 +00:00
/* rdp_inst->ui_warning = PLACEHOLDER */
/* rdp_inst->ui_unimpl = PLACEHOLDER */
/* rdp_inst->ui_begin_update = PLACEHOLDER */
/* rdp_inst->ui_end_update = PLACEHOLDER */
/* rdp_inst->ui_desktop_save = PLACEHOLDER */
/* rdp_inst->ui_desktop_restore = PLACEHOLDER */
/* rdp_inst->ui_create_bitmap = PLACEHOLDER */
/* rdp_inst->ui_paint_bitmap = PLACEHOLDER */
/* rdp_inst->ui_destroy_bitmap = PLACEHOLDER */
/* rdp_inst->ui_line = PLACEHOLDER */
/* rdp_inst->ui_rect = PLACEHOLDER */
/* rdp_inst->ui_polygon = PLACEHOLDER */
/* rdp_inst->ui_polyline = PLACEHOLDER */
/* rdp_inst->ui_ellipse = PLACEHOLDER */
/* rdp_inst->ui_start_draw_glyphs = PLACEHOLDER */
/* rdp_inst->ui_draw_glyph = PLACEHOLDER */
/* rdp_inst->ui_end_draw_glyphs = PLACEHOLDER */
/* rdp_inst->ui_get_toggle_keys_state = PLACEHOLDER */
/* rdp_inst->ui_bell = PLACEHOLDER */
/* rdp_inst->ui_destblt = PLACEHOLDER */
/* rdp_inst->ui_patblt = PLACEHOLDER */
/* rdp_inst->ui_screenblt = PLACEHOLDER */
/* rdp_inst->ui_memblt = PLACEHOLDER */
/* rdp_inst->ui_triblt = PLACEHOLDER */
/* rdp_inst->ui_create_glyph = PLACEHOLDER */
/* rdp_inst->ui_destroy_glyph = PLACEHOLDER */
rdp_inst->ui_select = guac_rdp_ui_select;
/* rdp_inst->ui_set_clip = PLACEHOLDER */
/* rdp_inst->ui_reset_clip = PLACEHOLDER */
/* rdp_inst->ui_resize_window = PLACEHOLDER */
/* rdp_inst->ui_set_cursor = PLACEHOLDER */
/* rdp_inst->ui_destroy_cursor = PLACEHOLDER */
/* rdp_inst->ui_create_cursor = PLACEHOLDER */
/* rdp_inst->ui_set_null_cursor = PLACEHOLDER */
/* rdp_inst->ui_set_default_cursor = PLACEHOLDER */
/* rdp_inst->ui_create_colourmap = PLACEHOLDER */
/* rdp_inst->ui_move_pointer = PLACEHOLDER */
/* rdp_inst->ui_set_colourmap = PLACEHOLDER */
/* rdp_inst->ui_create_surface = PLACEHOLDER */
/* rdp_inst->ui_set_surface = PLACEHOLDER */
/* rdp_inst->ui_destroy_surface = PLACEHOLDER */
/* rdp_inst->ui_channel_data = PLACEHOLDER */
2011-03-26 06:48:39 +00:00
/* Init chanman (pre-connect) */
if (freerdp_chanman_pre_connect(chanman, rdp_inst)) {
guac_send_error(client->io, "Error initializing RDP client channel manager");
guac_flush(client->io);
return 1;
}
/* Connect to RDP server */
if (rdp_inst->rdp_connect(rdp_inst)) {
2011-03-27 02:14:39 +00:00
guac_send_error(client->io, "Error connecting to RDP server");
2011-03-26 06:48:39 +00:00
guac_flush(client->io);
return 1;
}
/* Init chanman (post-connect) */
if (freerdp_chanman_post_connect(chanman, rdp_inst)) {
guac_send_error(client->io, "Error initializing RDP client channel manager");
guac_flush(client->io);
return 1;
}
2011-03-26 05:59:39 +00:00
/* Client handlers */
client->free_handler = rdp_guac_client_free_handler;
2011-03-26 05:49:48 +00:00
2011-03-26 04:58:46 +00:00
/* STUB */
guac_send_error(client->io, "STUB");
2011-03-26 05:49:48 +00:00
return 1;
2011-03-26 04:58:46 +00:00
}