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-02-16 02:47:51 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-02-16 02:47:51 +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
|
|
|
*/
|
|
|
|
|
2014-01-01 22:44:28 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "client.h"
|
2016-03-01 05:42:57 +00:00
|
|
|
#include "user.h"
|
|
|
|
#include "vnc.h"
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2015-07-11 05:12:30 +00:00
|
|
|
#ifdef ENABLE_COMMON_SSH
|
|
|
|
#include "guac_sftp.h"
|
|
|
|
#include "guac_ssh.h"
|
|
|
|
#include "sftp.h"
|
|
|
|
#endif
|
|
|
|
|
2013-08-09 00:25:08 +00:00
|
|
|
#ifdef ENABLE_PULSE
|
2016-12-25 09:13:40 +00:00
|
|
|
#include "pulse/pulse.h"
|
2013-10-26 00:49:22 +00:00
|
|
|
#endif
|
2013-09-19 21:41:28 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
#include <guacamole/client.h>
|
2013-08-09 01:43:03 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-12-08 21:14:04 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
int guac_client_init(guac_client* client) {
|
2011-03-20 07:22:22 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
/* Set client args */
|
|
|
|
client->args = GUAC_VNC_CLIENT_ARGS;
|
2010-12-08 21:14:04 +00:00
|
|
|
|
|
|
|
/* Alloc client data */
|
2016-03-01 05:42:57 +00:00
|
|
|
guac_vnc_client* vnc_client = calloc(1, sizeof(guac_vnc_client));
|
|
|
|
client->data = vnc_client;
|
2013-09-19 21:41:28 +00:00
|
|
|
|
2014-04-08 23:42:10 +00:00
|
|
|
/* Init clipboard */
|
2016-03-01 05:42:57 +00:00
|
|
|
vnc_client->clipboard = guac_common_clipboard_alloc(GUAC_VNC_CLIPBOARD_MAX_LENGTH);
|
2014-04-08 23:42:10 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
/* Set handlers */
|
|
|
|
client->join_handler = guac_vnc_user_join_handler;
|
2016-04-19 01:58:16 +00:00
|
|
|
client->leave_handler = guac_vnc_user_leave_handler;
|
2016-03-01 05:42:57 +00:00
|
|
|
client->free_handler = guac_vnc_client_free_handler;
|
2011-02-11 06:56:47 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-02-11 06:56:47 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
int guac_vnc_client_free_handler(guac_client* client) {
|
2014-04-11 19:56:06 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
guac_vnc_client* vnc_client = (guac_vnc_client*) client->data;
|
|
|
|
guac_vnc_settings* settings = vnc_client->settings;
|
2013-08-27 04:50:54 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
/* Clean up VNC client*/
|
|
|
|
rfbClient* rfb_client = vnc_client->rfb_client;
|
|
|
|
if (rfb_client != NULL) {
|
2013-02-10 00:39:31 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
/* Wait for client thread to finish */
|
|
|
|
pthread_join(vnc_client->client_thread, NULL);
|
2013-08-21 20:43:47 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
/* Free memory not free'd by libvncclient's rfbClientCleanup() */
|
|
|
|
if (rfb_client->frameBuffer != NULL) free(rfb_client->frameBuffer);
|
|
|
|
if (rfb_client->raw_buffer != NULL) free(rfb_client->raw_buffer);
|
|
|
|
if (rfb_client->rcSource != NULL) free(rfb_client->rcSource);
|
2013-02-10 00:46:29 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
/* Free VNC rfbClientData linked list (not free'd by rfbClientCleanup()) */
|
|
|
|
while (rfb_client->clientData != NULL) {
|
|
|
|
rfbClientData* next = rfb_client->clientData->next;
|
|
|
|
free(rfb_client->clientData);
|
|
|
|
rfb_client->clientData = next;
|
2013-04-30 07:47:38 +00:00
|
|
|
}
|
2013-08-09 01:43:03 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
rfbClientCleanup(rfb_client);
|
2013-08-09 01:43:03 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
}
|
2013-04-30 07:47:38 +00:00
|
|
|
|
2015-07-11 04:37:53 +00:00
|
|
|
#ifdef ENABLE_COMMON_SSH
|
2016-03-01 05:42:57 +00:00
|
|
|
/* Free SFTP filesystem, if loaded */
|
|
|
|
if (vnc_client->sftp_filesystem)
|
|
|
|
guac_common_ssh_destroy_sftp_filesystem(vnc_client->sftp_filesystem);
|
2015-07-11 04:37:53 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
/* Free SFTP session */
|
|
|
|
if (vnc_client->sftp_session)
|
|
|
|
guac_common_ssh_destroy_session(vnc_client->sftp_session);
|
2015-07-11 04:37:53 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
/* Free SFTP user */
|
|
|
|
if (vnc_client->sftp_user)
|
|
|
|
guac_common_ssh_destroy_user(vnc_client->sftp_user);
|
2015-07-11 04:37:53 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
guac_common_ssh_uninit();
|
2015-07-11 04:37:53 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
/* Free clipboard */
|
|
|
|
if (vnc_client->clipboard != NULL)
|
|
|
|
guac_common_clipboard_free(vnc_client->clipboard);
|
2013-08-21 20:43:47 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
/* Free display */
|
|
|
|
if (vnc_client->display != NULL)
|
|
|
|
guac_common_display_free(vnc_client->display);
|
2013-08-21 20:43:47 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
#ifdef ENABLE_PULSE
|
2016-12-25 09:13:40 +00:00
|
|
|
/* If audio enabled, stop streaming */
|
|
|
|
if (vnc_client->audio)
|
|
|
|
guac_pa_stream_free(vnc_client->audio);
|
2016-03-01 05:42:57 +00:00
|
|
|
#endif
|
2013-08-21 20:43:47 +00:00
|
|
|
|
2016-12-25 09:13:40 +00:00
|
|
|
/* Free parsed settings */
|
|
|
|
if (settings != NULL)
|
2016-03-01 05:42:57 +00:00
|
|
|
guac_vnc_settings_free(settings);
|
2014-01-02 20:32:25 +00:00
|
|
|
|
2016-03-01 05:42:57 +00:00
|
|
|
/* Free generic data struct */
|
|
|
|
free(client->data);
|
2010-12-08 21:14:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|