2013-12-29 04:53:12 +00:00
|
|
|
/*
|
2016-03-25 19:59:40 +00:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
2011-12-30 08:10:28 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-12-30 08:10:28 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2013-12-29 04:53:12 +00:00
|
|
|
*/
|
|
|
|
|
2020-01-04 21:07:28 +00:00
|
|
|
#include "client.h"
|
2019-12-23 20:48:22 +00:00
|
|
|
#include "channels/audio-input.h"
|
2020-01-04 21:07:28 +00:00
|
|
|
#include "channels/cliprdr.h"
|
2019-12-23 20:48:22 +00:00
|
|
|
#include "channels/disp.h"
|
2019-12-23 21:29:13 +00:00
|
|
|
#include "common/recording.h"
|
2020-01-04 21:07:28 +00:00
|
|
|
#include "config.h"
|
2019-12-23 20:48:22 +00:00
|
|
|
#include "fs.h"
|
2019-12-30 02:44:41 +00:00
|
|
|
#include "log.h"
|
2019-12-23 21:29:13 +00:00
|
|
|
#include "rdp.h"
|
2020-01-04 21:07:28 +00:00
|
|
|
#include "settings.h"
|
2016-03-01 05:50:00 +00:00
|
|
|
#include "user.h"
|
2014-01-01 22:44:28 +00:00
|
|
|
|
2015-07-11 05:12:30 +00:00
|
|
|
#ifdef ENABLE_COMMON_SSH
|
2017-02-27 22:28:23 +00:00
|
|
|
#include "common-ssh/sftp.h"
|
|
|
|
#include "common-ssh/ssh.h"
|
|
|
|
#include "common-ssh/user.h"
|
2015-07-11 05:12:30 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-31 21:25:31 +00:00
|
|
|
#include <guacamole/audio.h>
|
2014-01-01 22:44:28 +00:00
|
|
|
#include <guacamole/client.h>
|
2013-07-18 16:34:02 +00:00
|
|
|
|
2014-06-11 01:45:14 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdlib.h>
|
2012-03-21 17:45:40 +00:00
|
|
|
|
2011-12-30 08:10:28 +00:00
|
|
|
int guac_client_init(guac_client* client, int argc, char** argv) {
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Set client args */
|
|
|
|
client->args = GUAC_RDP_CLIENT_ARGS;
|
2012-12-26 03:36:19 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Alloc client data */
|
|
|
|
guac_rdp_client* rdp_client = calloc(1, sizeof(guac_rdp_client));
|
|
|
|
client->data = rdp_client;
|
2013-08-24 08:17:27 +00:00
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
/* Init clipboard */
|
2019-10-12 00:01:26 +00:00
|
|
|
rdp_client->clipboard = guac_rdp_clipboard_alloc(client);
|
2016-03-16 04:23:19 +00:00
|
|
|
|
|
|
|
/* Init display update module */
|
|
|
|
rdp_client->disp = guac_rdp_disp_alloc();
|
2013-08-24 19:37:43 +00:00
|
|
|
|
2019-12-30 02:44:41 +00:00
|
|
|
/* Redirect FreeRDP log messages to guac_client_log() */
|
|
|
|
guac_rdp_redirect_wlog(client);
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Recursive attribute for locks */
|
|
|
|
pthread_mutexattr_init(&(rdp_client->attributes));
|
|
|
|
pthread_mutexattr_settype(&(rdp_client->attributes),
|
|
|
|
PTHREAD_MUTEX_RECURSIVE);
|
2013-08-24 19:37:43 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Set handlers */
|
|
|
|
client->join_handler = guac_rdp_user_join_handler;
|
|
|
|
client->free_handler = guac_rdp_client_free_handler;
|
2013-08-27 04:26:38 +00:00
|
|
|
|
2016-03-30 19:20:49 +00:00
|
|
|
#ifdef ENABLE_COMMON_SSH
|
|
|
|
guac_common_ssh_init(client);
|
|
|
|
#endif
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
return 0;
|
2012-02-27 18:36:14 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
}
|
2013-01-23 09:34:51 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
int guac_rdp_client_free_handler(guac_client* client) {
|
2014-11-26 23:23:26 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
2012-10-02 21:09:57 +00:00
|
|
|
|
2016-03-05 00:03:09 +00:00
|
|
|
/* Wait for client thread */
|
|
|
|
pthread_join(rdp_client->client_thread, NULL);
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Free parsed settings */
|
|
|
|
if (rdp_client->settings != NULL)
|
|
|
|
guac_rdp_settings_free(rdp_client->settings);
|
2014-07-21 16:12:17 +00:00
|
|
|
|
2019-10-12 00:01:26 +00:00
|
|
|
/* Clean up clipboard */
|
|
|
|
guac_rdp_clipboard_free(rdp_client->clipboard);
|
|
|
|
|
2016-03-16 04:23:19 +00:00
|
|
|
/* Free display update module */
|
|
|
|
guac_rdp_disp_free(rdp_client->disp);
|
|
|
|
|
2016-03-30 19:20:49 +00:00
|
|
|
/* Clean up filesystem, if allocated */
|
|
|
|
if (rdp_client->filesystem != NULL)
|
|
|
|
guac_rdp_fs_free(rdp_client->filesystem);
|
|
|
|
|
|
|
|
#ifdef ENABLE_COMMON_SSH
|
|
|
|
/* Free SFTP filesystem, if loaded */
|
|
|
|
if (rdp_client->sftp_filesystem)
|
|
|
|
guac_common_ssh_destroy_sftp_filesystem(rdp_client->sftp_filesystem);
|
|
|
|
|
|
|
|
/* Free SFTP session */
|
|
|
|
if (rdp_client->sftp_session)
|
|
|
|
guac_common_ssh_destroy_session(rdp_client->sftp_session);
|
|
|
|
|
|
|
|
/* Free SFTP user */
|
|
|
|
if (rdp_client->sftp_user)
|
|
|
|
guac_common_ssh_destroy_user(rdp_client->sftp_user);
|
|
|
|
|
|
|
|
guac_common_ssh_uninit();
|
|
|
|
#endif
|
|
|
|
|
2017-11-27 17:38:20 +00:00
|
|
|
/* Clean up recording, if in progress */
|
|
|
|
if (rdp_client->recording != NULL)
|
|
|
|
guac_common_recording_free(rdp_client->recording);
|
|
|
|
|
2016-03-31 21:25:31 +00:00
|
|
|
/* Clean up audio stream, if allocated */
|
|
|
|
if (rdp_client->audio != NULL)
|
|
|
|
guac_audio_stream_free(rdp_client->audio);
|
|
|
|
|
2016-04-18 07:32:51 +00:00
|
|
|
/* Clean up audio input buffer, if allocated */
|
|
|
|
if (rdp_client->audio_input != NULL)
|
|
|
|
guac_rdp_audio_buffer_free(rdp_client->audio_input);
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Free client data */
|
|
|
|
free(rdp_client);
|
2011-12-30 08:10:28 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|