2014-05-07 18:32:19 +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
|
2014-05-07 18:32:19 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-05-07 18:32:19 +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-05-07 18:32:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2020-07-02 02:02:50 +00:00
|
|
|
#include "argv.h"
|
2014-05-07 18:32:19 +00:00
|
|
|
#include "client.h"
|
2017-11-27 17:38:20 +00:00
|
|
|
#include "common/recording.h"
|
2016-03-15 02:47:36 +00:00
|
|
|
#include "settings.h"
|
|
|
|
#include "telnet.h"
|
2017-02-27 22:34:46 +00:00
|
|
|
#include "terminal/terminal.h"
|
2016-03-15 02:47:36 +00:00
|
|
|
#include "user.h"
|
2014-05-07 18:32:19 +00:00
|
|
|
|
2014-06-02 23:01:13 +00:00
|
|
|
#include <langinfo.h>
|
|
|
|
#include <locale.h>
|
2014-05-07 18:32:19 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-07-02 02:02:50 +00:00
|
|
|
#include <guacamole/argv.h>
|
2014-05-07 18:32:19 +00:00
|
|
|
#include <guacamole/client.h>
|
|
|
|
|
2016-03-15 02:47:36 +00:00
|
|
|
int guac_client_init(guac_client* client) {
|
2014-05-07 18:32:19 +00:00
|
|
|
|
2016-03-15 02:47:36 +00:00
|
|
|
/* Set client args */
|
|
|
|
client->args = GUAC_TELNET_CLIENT_ARGS;
|
2014-05-07 18:32:19 +00:00
|
|
|
|
2016-03-15 02:47:36 +00:00
|
|
|
/* Allocate client instance data */
|
|
|
|
guac_telnet_client* telnet_client = calloc(1, sizeof(guac_telnet_client));
|
|
|
|
client->data = telnet_client;
|
2014-05-07 18:32:19 +00:00
|
|
|
|
2018-07-31 06:01:27 +00:00
|
|
|
/* Init clipboard */
|
|
|
|
telnet_client->clipboard = guac_common_clipboard_alloc(GUAC_TELNET_CLIPBOARD_MAX_LENGTH);
|
|
|
|
|
2016-03-15 02:47:36 +00:00
|
|
|
/* Init telnet client */
|
|
|
|
telnet_client->socket_fd = -1;
|
|
|
|
telnet_client->naws_enabled = 0;
|
|
|
|
telnet_client->echo_enabled = 1;
|
2014-05-07 18:32:19 +00:00
|
|
|
|
2016-03-15 02:47:36 +00:00
|
|
|
/* Set handlers */
|
|
|
|
client->join_handler = guac_telnet_user_join_handler;
|
|
|
|
client->free_handler = guac_telnet_client_free_handler;
|
2014-05-07 18:32:19 +00:00
|
|
|
|
2020-07-02 02:02:50 +00:00
|
|
|
/* Register handlers for argument values that may be sent after the handshake */
|
|
|
|
guac_argv_register(GUAC_TELNET_ARGV_COLOR_SCHEME, guac_telnet_argv_callback, NULL, GUAC_ARGV_OPTION_ECHO);
|
|
|
|
guac_argv_register(GUAC_TELNET_ARGV_FONT_NAME, guac_telnet_argv_callback, NULL, GUAC_ARGV_OPTION_ECHO);
|
|
|
|
guac_argv_register(GUAC_TELNET_ARGV_FONT_SIZE, guac_telnet_argv_callback, NULL, GUAC_ARGV_OPTION_ECHO);
|
|
|
|
|
2014-06-02 23:01:13 +00:00
|
|
|
/* Set locale and warn if not UTF-8 */
|
|
|
|
setlocale(LC_CTYPE, "");
|
2016-03-15 02:47:36 +00:00
|
|
|
if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
|
|
|
|
guac_client_log(client, GUAC_LOG_INFO,
|
|
|
|
"Current locale does not use UTF-8. Some characters may "
|
|
|
|
"not render correctly.");
|
2014-07-02 20:19:12 +00:00
|
|
|
}
|
2014-05-07 18:32:19 +00:00
|
|
|
|
2016-03-15 02:47:36 +00:00
|
|
|
/* Success */
|
|
|
|
return 0;
|
2014-05-07 18:32:19 +00:00
|
|
|
|
2016-03-15 02:47:36 +00:00
|
|
|
}
|
2014-05-07 18:32:19 +00:00
|
|
|
|
2016-03-15 02:47:36 +00:00
|
|
|
int guac_telnet_client_free_handler(guac_client* client) {
|
2016-01-27 20:40:35 +00:00
|
|
|
|
2016-03-15 02:47:36 +00:00
|
|
|
guac_telnet_client* telnet_client = (guac_telnet_client*) client->data;
|
2016-01-27 20:40:35 +00:00
|
|
|
|
2016-03-15 02:47:36 +00:00
|
|
|
/* Close telnet connection */
|
|
|
|
if (telnet_client->socket_fd != -1)
|
|
|
|
close(telnet_client->socket_fd);
|
2016-01-27 20:40:35 +00:00
|
|
|
|
2017-11-27 17:38:20 +00:00
|
|
|
/* Clean up recording, if in progress */
|
|
|
|
if (telnet_client->recording != NULL)
|
|
|
|
guac_common_recording_free(telnet_client->recording);
|
|
|
|
|
2016-03-15 02:47:36 +00:00
|
|
|
/* Kill terminal */
|
|
|
|
guac_terminal_free(telnet_client->term);
|
2016-01-27 20:40:35 +00:00
|
|
|
|
2016-03-15 02:47:36 +00:00
|
|
|
/* Wait for and free telnet session, if connected */
|
|
|
|
if (telnet_client->telnet != NULL) {
|
|
|
|
pthread_join(telnet_client->client_thread, NULL);
|
|
|
|
telnet_free(telnet_client->telnet);
|
2016-01-27 20:40:35 +00:00
|
|
|
}
|
|
|
|
|
2016-03-15 02:47:36 +00:00
|
|
|
/* Free settings */
|
|
|
|
if (telnet_client->settings != NULL)
|
|
|
|
guac_telnet_settings_free(telnet_client->settings);
|
2014-05-07 18:32:19 +00:00
|
|
|
|
2018-07-31 06:01:27 +00:00
|
|
|
guac_common_clipboard_free(telnet_client->clipboard);
|
2016-03-15 02:47:36 +00:00
|
|
|
free(telnet_client);
|
2014-05-07 18:32:19 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|