Commit 30df12aa authored by Felipe Borges's avatar Felipe Borges 👣

frdp-session: Refactor freerdp initialization routine

By spliting it in its own function we will be able to handle
successive authentication attempts in a sane way whereas memory
should be more managable, avoiding leaks.
parent 5a7ba256
......@@ -333,7 +333,7 @@ frdp_display_init (FrdpDisplay *self)
gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE);
priv->session = NULL;
priv->session = frdp_session_new (self);
}
/**
......@@ -354,7 +354,6 @@ frdp_display_open_host (FrdpDisplay *display,
g_return_if_fail (host != NULL);
priv->session = frdp_session_new (display);
g_signal_connect (priv->session, "rdp-disconnected",
G_CALLBACK (frdp_display_disconnected),
display);
......
......@@ -39,6 +39,11 @@ struct _FrdpSessionPrivate
guint update_id;
gboolean is_connected;
gchar *hostname;
gchar *username;
gchar *password;
guint port;
};
G_DEFINE_TYPE_WITH_PRIVATE (FrdpSession, frdp_session, G_TYPE_OBJECT)
......@@ -117,45 +122,6 @@ frdp_session_draw (GtkWidget *widget,
return TRUE;
}
static void
frdp_session_set_hostname (FrdpSession *self,
const gchar *hostname)
{
rdpSettings *settings = self->priv->freerdp_session->settings;
g_free (settings->ServerHostname);
settings->ServerHostname = g_strdup (hostname);
}
static void
frdp_session_set_port (FrdpSession *self,
guint port)
{
rdpSettings *settings = self->priv->freerdp_session->settings;
settings->ServerPort = port;
}
static void
frdp_session_set_username (FrdpSession *self,
const gchar *username)
{
rdpSettings *settings = self->priv->freerdp_session->settings;
g_free (settings->Username);
settings->Username = g_strdup (username);
}
static void
frdp_session_set_password (FrdpSession *self,
const gchar *password)
{
rdpSettings *settings = self->priv->freerdp_session->settings;
g_free (settings->Password);
settings->Password = g_strdup (password);
}
static guint
frdp_certificate_verify (freerdp *freerdp_session,
const gchar *common_name,
......@@ -364,6 +330,32 @@ update (gpointer user_data)
return TRUE;
}
static void
frdp_session_init_freerdp (FrdpSession *self)
{
FrdpSessionPrivate *priv = self->priv;
rdpSettings *settings;
/* Setup FreeRDP session */
priv->freerdp_session = freerdp_new ();
priv->freerdp_session->PreConnect = frdp_pre_connect;
priv->freerdp_session->PostConnect = frdp_post_connect;
priv->freerdp_session->Authenticate = frdp_authenticate;
priv->freerdp_session->VerifyCertificate = frdp_certificate_verify;
priv->freerdp_session->ContextSize = sizeof (frdpContext);
freerdp_context_new (priv->freerdp_session);
((frdpContext *) priv->freerdp_session->context)->self = self;
settings = priv->freerdp_session->settings;
settings->ServerHostname = g_strdup (priv->hostname);
settings->ServerPort = priv->port;
settings->Username = g_strdup (priv->username);
settings->Password = g_strdup (priv->password);
}
static void
frdp_session_connect_thread (GTask *task,
gpointer source_object,
......@@ -435,16 +427,19 @@ frdp_session_set_property (GObject *object,
switch (property_id)
{
case PROP_HOSTNAME:
frdp_session_set_hostname (self, g_value_get_string (value));
g_free (self->priv->hostname);
self->priv->hostname = g_value_dup_string (value);
break;
case PROP_PORT:
frdp_session_set_port (self, g_value_get_uint (value));
self->priv->port = g_value_get_uint (value);
break;
case PROP_USERNAME:
frdp_session_set_username (self, g_value_get_string (value));
g_free (self->priv->username);
self->priv->username = g_value_dup_string (value);
break;
case PROP_PASSWORD:
frdp_session_set_password (self, g_value_get_string (value));
g_free (self->priv->password);
self->priv->password = g_value_dup_string (value);
break;
case PROP_DISPLAY:
self->priv->display = g_value_get_object (value);
......@@ -472,6 +467,10 @@ frdp_session_finalize (GObject *object)
frdp_session_close (self);
g_clear_pointer (&self->priv->hostname, g_free);
g_clear_pointer (&self->priv->username, g_free);
g_clear_pointer (&self->priv->password, g_free);
G_OBJECT_CLASS (frdp_session_parent_class)->finalize (object);
}
......@@ -565,26 +564,15 @@ frdp_session_connect (FrdpSession *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
FrdpSessionPrivate *priv = self->priv;
GTask *task;
if (!self->priv->is_connected) {
/* Setup FreeRDP session */
priv->freerdp_session = freerdp_new ();
priv->freerdp_session->PreConnect = frdp_pre_connect;
priv->freerdp_session->PostConnect = frdp_post_connect;
priv->freerdp_session->Authenticate = frdp_authenticate;
priv->freerdp_session->VerifyCertificate = frdp_certificate_verify;
priv->freerdp_session->ContextSize = sizeof (frdpContext);
self->priv->hostname = g_strdup (hostname);
self->priv->port = port;
freerdp_context_new (priv->freerdp_session);
((frdpContext *) priv->freerdp_session->context)->self = self;
if (!self->priv->is_connected) {
frdp_session_init_freerdp (self);
}
frdp_session_set_hostname (self, hostname);
frdp_session_set_port (self, port);
task = g_task_new (self, cancellable, callback, user_data);
g_task_run_in_thread (task, frdp_session_connect_thread);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment