2018-09-10 03:03: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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "client.h"
|
2018-09-11 04:05:23 +00:00
|
|
|
#include "common/clipboard.h"
|
2018-09-10 03:03:40 +00:00
|
|
|
#include "kubernetes.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "user.h"
|
|
|
|
|
2018-09-11 04:05:23 +00:00
|
|
|
#include <guacamole/client.h>
|
|
|
|
#include <libwebsockets.h>
|
|
|
|
|
2018-09-10 03:03:40 +00:00
|
|
|
#include <langinfo.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-09-10 22:01:48 +00:00
|
|
|
/**
|
|
|
|
* Static reference to the guac_client associated with the active Kubernetes
|
|
|
|
* connection. As guacd guarantees that each main client connection is
|
|
|
|
* isolated within its own process, this is safe.
|
|
|
|
*/
|
|
|
|
static guac_client* guac_kubernetes_lws_log_client = NULL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logging callback invoked by libwebsockets to log a single line of logging
|
|
|
|
* output. As libwebsockets messages are all generally low-level, the log
|
|
|
|
* level provided by libwebsockets is ignored here, with all messages logged
|
|
|
|
* instead at guacd's debug level.
|
|
|
|
*
|
|
|
|
* @param level
|
|
|
|
* The libwebsockets log level associated with the log message. This value
|
|
|
|
* is ignored by this implementation of the logging callback.
|
|
|
|
*
|
|
|
|
* @param line
|
|
|
|
* The line of logging output to log.
|
|
|
|
*/
|
|
|
|
static void guac_kubernetes_log(int level, const char* line) {
|
|
|
|
if (guac_kubernetes_lws_log_client != NULL)
|
|
|
|
guac_client_log(guac_kubernetes_lws_log_client, GUAC_LOG_DEBUG,
|
|
|
|
"libwebsockets: %s", line);
|
|
|
|
}
|
|
|
|
|
2018-09-10 03:03:40 +00:00
|
|
|
int guac_client_init(guac_client* client) {
|
|
|
|
|
2018-09-10 22:01:48 +00:00
|
|
|
/* Redirect libwebsockets logging */
|
|
|
|
guac_kubernetes_lws_log_client = client;
|
|
|
|
lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_INFO,
|
|
|
|
guac_kubernetes_log);
|
|
|
|
|
2018-09-10 03:03:40 +00:00
|
|
|
/* Set client args */
|
|
|
|
client->args = GUAC_KUBERNETES_CLIENT_ARGS;
|
|
|
|
|
|
|
|
/* Allocate client instance data */
|
|
|
|
guac_kubernetes_client* kubernetes_client = calloc(1, sizeof(guac_kubernetes_client));
|
|
|
|
client->data = kubernetes_client;
|
|
|
|
|
|
|
|
/* Init clipboard */
|
|
|
|
kubernetes_client->clipboard = guac_common_clipboard_alloc(GUAC_KUBERNETES_CLIPBOARD_MAX_LENGTH);
|
|
|
|
|
|
|
|
/* Set handlers */
|
|
|
|
client->join_handler = guac_kubernetes_user_join_handler;
|
|
|
|
client->free_handler = guac_kubernetes_client_free_handler;
|
|
|
|
|
|
|
|
/* Set locale and warn if not UTF-8 */
|
|
|
|
setlocale(LC_CTYPE, "");
|
|
|
|
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.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Success */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int guac_kubernetes_client_free_handler(guac_client* client) {
|
|
|
|
|
|
|
|
guac_kubernetes_client* kubernetes_client =
|
|
|
|
(guac_kubernetes_client*) client->data;
|
|
|
|
|
2018-09-10 08:26:13 +00:00
|
|
|
/* Wait client thread to terminate */
|
|
|
|
pthread_join(kubernetes_client->client_thread, NULL);
|
2018-09-10 03:03:40 +00:00
|
|
|
|
|
|
|
/* Free settings */
|
|
|
|
if (kubernetes_client->settings != NULL)
|
|
|
|
guac_kubernetes_settings_free(kubernetes_client->settings);
|
|
|
|
|
|
|
|
guac_common_clipboard_free(kubernetes_client->clipboard);
|
|
|
|
free(kubernetes_client);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|