guacamole-spice-protocol/src/protocols/vnc/client.c

129 lines
3.7 KiB
C
Raw Normal View History

/*
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.
*/
2014-01-01 22:44:28 +00:00
#include "config.h"
#include "client.h"
#include "user.h"
#include "vnc.h"
2010-12-08 21:14:04 +00:00
#ifdef ENABLE_COMMON_SSH
#include "common-ssh/sftp.h"
#include "common-ssh/ssh.h"
#include "common-ssh/user.h"
#endif
2013-08-09 00:25:08 +00:00
#ifdef ENABLE_PULSE
#include "pulse/pulse.h"
#endif
2013-09-19 21:41:28 +00:00
#include <guacamole/client.h>
#include <stdlib.h>
#include <string.h>
2010-12-08 21:14:04 +00:00
int guac_client_init(guac_client* client) {
2011-03-20 07:22:22 +00:00
/* Set client args */
client->args = GUAC_VNC_CLIENT_ARGS;
2010-12-08 21:14:04 +00:00
/* Alloc client data */
guac_vnc_client* vnc_client = calloc(1, sizeof(guac_vnc_client));
client->data = vnc_client;
2013-09-19 21:41:28 +00:00
/* Init clipboard */
vnc_client->clipboard = guac_common_clipboard_alloc(GUAC_VNC_CLIPBOARD_MAX_LENGTH);
/* Set handlers */
client->join_handler = guac_vnc_user_join_handler;
client->leave_handler = guac_vnc_user_leave_handler;
client->free_handler = guac_vnc_client_free_handler;
2011-02-11 06:56:47 +00:00
return 0;
}
2011-02-11 06:56:47 +00:00
int guac_vnc_client_free_handler(guac_client* client) {
guac_vnc_client* vnc_client = (guac_vnc_client*) client->data;
guac_vnc_settings* settings = vnc_client->settings;
/* Clean up VNC client*/
rfbClient* rfb_client = vnc_client->rfb_client;
if (rfb_client != NULL) {
2013-02-10 00:39:31 +00:00
/* Wait for client thread to finish */
pthread_join(vnc_client->client_thread, NULL);
2013-08-21 20:43:47 +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);
/* 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;
}
rfbClientCleanup(rfb_client);
}
#ifdef ENABLE_COMMON_SSH
/* Free SFTP filesystem, if loaded */
if (vnc_client->sftp_filesystem)
guac_common_ssh_destroy_sftp_filesystem(vnc_client->sftp_filesystem);
/* Free SFTP session */
if (vnc_client->sftp_session)
guac_common_ssh_destroy_session(vnc_client->sftp_session);
/* Free SFTP user */
if (vnc_client->sftp_user)
guac_common_ssh_destroy_user(vnc_client->sftp_user);
guac_common_ssh_uninit();
#endif
/* Free clipboard */
if (vnc_client->clipboard != NULL)
guac_common_clipboard_free(vnc_client->clipboard);
2013-08-21 20:43:47 +00:00
/* Free display */
if (vnc_client->display != NULL)
guac_common_display_free(vnc_client->display);
2013-08-21 20:43:47 +00:00
#ifdef ENABLE_PULSE
/* If audio enabled, stop streaming */
if (vnc_client->audio)
guac_pa_stream_free(vnc_client->audio);
#endif
2013-08-21 20:43:47 +00:00
/* Free parsed settings */
if (settings != NULL)
guac_vnc_settings_free(settings);
/* Free generic data struct */
free(client->data);
2010-12-08 21:14:04 +00:00
return 0;
}