Skip to content

Commit

Permalink
Merge pull request #359 from giox069/master
Browse files Browse the repository at this point in the history
Add printer and smartcard redirection, fix freerdp connection closing
  • Loading branch information
antenore committed Oct 20, 2014
2 parents 36039db + c21e728 commit efb7b5f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 63 deletions.
118 changes: 57 additions & 61 deletions remmina-plugins/rdp/rdp_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330,
* Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* In addition, as a special exception, the copyright holders give
Expand Down Expand Up @@ -338,6 +338,7 @@ static BOOL remmina_rdp_post_connect(freerdp* instance)
instance->update->DesktopResize = rf_desktop_resize;

freerdp_channels_post_connect(instance->context->channels, instance);
rfi->connected = True;

remmina_plugin_service->protocol_plugin_emit_signal(gp, "connect");

Expand Down Expand Up @@ -375,21 +376,21 @@ static BOOL remmina_rdp_authenticate(freerdp* instance, char** username, char**

s_domain = remmina_plugin_service->protocol_plugin_init_get_domain(gp);
if (s_domain) rfi->settings->Domain = strdup(s_domain);

save = remmina_plugin_service->protocol_plugin_init_get_savepassword(gp);
if (save)
{
// User has requested to save password. We put all the new cretentials
// into remminafile->settings. They will be saved later, when disconnecting, by
// remmina_connection_object_on_disconnect of remmina_connection_window.c
// (this operation should be called "save credentials" and not "save password")

remmina_plugin_service->file_set_string( remminafile, "username", s_username );
remmina_plugin_service->file_set_string( remminafile, "password", s_password );
remmina_plugin_service->file_set_string( remminafile, "domain", s_domain );

}

if ( s_username ) g_free( s_username );
if ( s_password ) g_free( s_password );
if ( s_domain ) g_free( s_domain );
Expand Down Expand Up @@ -470,9 +471,9 @@ static void remmina_rdp_main_loop(RemminaProtocolWidget* gp)
fd_set wfds_set;
rfContext* rfi;
wMessage* event;

rdpChannels *channels;


memset(rfds, 0, sizeof(rfds));
memset(wfds, 0, sizeof(wfds));
Expand Down Expand Up @@ -561,39 +562,18 @@ static void remmina_rdp_main_loop(RemminaProtocolWidget* gp)
}
}

gboolean remmina_rdp_load_plugin(rdpChannels* channels, rdpSettings* settings, const char* name, rdpSettings* plugin_data)
{
void* entry = NULL;

entry = freerdp_channels_client_find_static_entry("VirtualChannelEntry", name);

if (entry)
{
if (freerdp_channels_client_load(channels, settings, entry, plugin_data) == 0)
{
g_printf("loading channel %s (static)\n", name);
return TRUE;
}
}

g_printf("loading channel %s (plugin)\n", name);
freerdp_channels_load_plugin(channels, settings, name, plugin_data);

return TRUE;
}

int remmina_rdp_load_static_channel_addin(rdpChannels* channels, rdpSettings* settings, char* name, void* data)
{
void* entry;

entry = freerdp_load_channel_addin_entry(name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC);




if (entry)
{

if (freerdp_channels_client_load(channels, settings, entry, data) == 0)
{
fprintf(stderr, "loading channel %s\n", name);
Expand Down Expand Up @@ -630,7 +610,6 @@ static gboolean remmina_rdp_main(RemminaProtocolWidget* gp)
gint port;
gchar* host;
gchar* value;
gint rdpdr_num;
gint drdynvc_num;
gint rdpsnd_rate;
gint rdpsnd_channel;
Expand Down Expand Up @@ -664,7 +643,7 @@ static gboolean remmina_rdp_main(RemminaProtocolWidget* gp)
dest_server = remmina_plugin_service->file_get_string(remminafile, "server");
if ( dest_server ) {
remmina_plugin_service->get_server_port(dest_server, 0, &dest_host, &dest_port);
rfi->settings->CertificateName = _strdup( dest_host );
rfi->settings->CertificateName = strdup( dest_host );
g_free(dest_host);
}
}
Expand Down Expand Up @@ -701,12 +680,17 @@ static gboolean remmina_rdp_main(RemminaProtocolWidget* gp)

if (remmina_plugin_service->file_get_string(remminafile, "clientname"))
{
strncpy(rfi->settings->ClientHostname, remmina_plugin_service->file_get_string(remminafile, "clientname"),
sizeof(rfi->settings->ClientHostname) - 1);
s = remmina_plugin_service->file_get_string(remminafile, "clientname");
if ( s ) {
free( rfi->settings->ClientHostname );
rfi->settings->ClientHostname = strdup(s);
g_free(s);
}
}
else
{
strncpy(rfi->settings->ClientHostname, g_get_host_name(), sizeof(rfi->settings->ClientHostname) - 1);
free( rfi->settings->ClientHostname );
rfi->settings->ClientHostname = strdup( g_get_host_name() );
}

if (remmina_plugin_service->file_get_string(remminafile, "exec"))
Expand Down Expand Up @@ -829,7 +813,6 @@ static gboolean remmina_rdp_main(RemminaProtocolWidget* gp)

rfi->settings->RedirectClipboard = ( remmina_plugin_service->file_get_int(remminafile, "disableclipboard", FALSE) ? FALSE: TRUE );

rdpdr_num = 0;
cs = remmina_plugin_service->file_get_string(remminafile, "sharefolder");

if (cs && cs[0] == '/')
Expand All @@ -854,28 +837,32 @@ static gboolean remmina_rdp_main(RemminaProtocolWidget* gp)

freerdp_device_collection_add(rfi->settings, (RDPDR_DEVICE*) drive);
rfi->settings->DeviceRedirection = TRUE;
rdpdr_num++;
}

if (remmina_plugin_service->file_get_int(remminafile, "shareprinter", FALSE))
{
// rfi->rdpdr_data[rdpdr_num].size = sizeof(RDP_PLUGIN_DATA);
// rfi->rdpdr_data[rdpdr_num].data[0] = "printer";
rdpdr_num++;
RDPDR_PRINTER* printer;
printer = (RDPDR_PRINTER*) malloc(sizeof(RDPDR_PRINTER));
ZeroMemory(printer, sizeof(RDPDR_PRINTER));

printer->Type = RDPDR_DTYP_PRINT;

freerdp_device_collection_add(rfi->settings, (RDPDR_DEVICE*) printer);
rfi->settings->DeviceRedirection = TRUE;

}

if (remmina_plugin_service->file_get_int(remminafile, "sharesmartcard", FALSE))
{
//rfi->rdpdr_data[rdpdr_num].size = sizeof(RDP_PLUGIN_DATA);
//rfi->rdpdr_data[rdpdr_num].data[0] = "scard";
//rfi->rdpdr_data[rdpdr_num].data[1] = "scard";
rdpdr_num++;
}
RDPDR_SMARTCARD* smartcard;
smartcard = (RDPDR_SMARTCARD*) malloc(sizeof(RDPDR_SMARTCARD));
ZeroMemory(smartcard, sizeof(RDPDR_SMARTCARD));

if (rdpdr_num)
{
//remmina_rdp_load_plugin(rfi->channels, rfi->settings, "rdpdr", rfi->rdpdr_data);
remmina_rdp_load_plugin(rfi->instance->context->channels, rfi->settings, "rdpdr", rfi->settings);
smartcard->Type = RDPDR_DTYP_SMARTCARD;
smartcard->Name = _strdup("scard");

freerdp_device_collection_add(rfi->settings, (RDPDR_DEVICE*) smartcard);
rfi->settings->DeviceRedirection = TRUE;
}


Expand All @@ -889,7 +876,7 @@ static gboolean remmina_rdp_main(RemminaProtocolWidget* gp)

return FALSE;
}



remmina_rdp_main_loop(gp);
Expand Down Expand Up @@ -917,7 +904,7 @@ static void remmina_rdp_init(RemminaProtocolWidget* gp)
{
freerdp* instance;
rfContext* rfi;

freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0);

instance = freerdp_new();
Expand All @@ -938,6 +925,7 @@ static void remmina_rdp_init(RemminaProtocolWidget* gp)
rfi->instance = instance;
rfi->settings = instance->settings;
rfi->instance->context->channels = freerdp_channels_new();
rfi->connected = False;

pthread_mutex_init(&rfi->mutex, NULL);

Expand Down Expand Up @@ -972,7 +960,7 @@ static gboolean remmina_rdp_close_connection(RemminaProtocolWidget* gp)
{
rfContext* rfi;
freerdp* instance;


rfi = GET_DATA(gp);
instance = rfi->instance;
Expand All @@ -995,13 +983,12 @@ static gboolean remmina_rdp_close_connection(RemminaProtocolWidget* gp)

if (instance)
{
if (instance->context->channels)
{
//freerdp_channels_close(rfi->channels, instance);
freerdp_channels_free(instance->context->channels);
instance->context->channels = NULL;
if ( rfi->connected ) {
if (instance->context->channels)
freerdp_channels_close(instance->context->channels, instance);
freerdp_disconnect(instance);
rfi->connected = False;
}
freerdp_disconnect(instance);
}

if (rfi->rfx_context)
Expand All @@ -1012,8 +999,17 @@ static gboolean remmina_rdp_close_connection(RemminaProtocolWidget* gp)

if (instance)
{
//freerdp_context_free(instance); /* context is rfContext* rfi */
/* Remove instance->context from gp object data to avoid double free */
g_object_steal_data(G_OBJECT(gp), "plugin-data");

if (instance->context->channels) {
freerdp_channels_free(instance->context->channels);
instance->context->channels = NULL;
}

freerdp_context_free(instance); /* context is rfContext* rfi */
freerdp_free(instance);
rfi->instance = NULL;
}

return FALSE;
Expand Down
6 changes: 4 additions & 2 deletions remmina-plugins/rdp/rdp_plugin.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Remmina - The GTK+ Remote Desktop Client
* Copyright (C) 2010-2011 Vic Lee
* Copyright (C) 2010-2011 Vic Lee
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330,
* Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* In addition, as a special exception, the copyright holders give
Expand Down Expand Up @@ -106,6 +106,8 @@ struct rf_context

RFX_CONTEXT* rfx_context;

gboolean connected;

gboolean sw_gdi;
GtkWidget* drawing_area;
gint scale_width;
Expand Down

0 comments on commit efb7b5f

Please sign in to comment.