cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

argv.c (3243B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20#include "config.h"
     21#include "argv.h"
     22#include "kubernetes.h"
     23#include "terminal/terminal.h"
     24
     25#include <guacamole/protocol.h>
     26#include <guacamole/socket.h>
     27#include <guacamole/user.h>
     28
     29#include <stdlib.h>
     30#include <string.h>
     31
     32int guac_kubernetes_argv_callback(guac_user* user, const char* mimetype,
     33        const char* name, const char* value, void* data) {
     34
     35    guac_client* client = user->client;
     36    guac_kubernetes_client* kubernetes_client = (guac_kubernetes_client*) client->data;
     37    guac_terminal* terminal = kubernetes_client->term;
     38
     39    /* Update color scheme */
     40    if (strcmp(name, GUAC_KUBERNETES_ARGV_COLOR_SCHEME) == 0)
     41        guac_terminal_apply_color_scheme(terminal, value);
     42
     43    /* Update font name */
     44    else if (strcmp(name, GUAC_KUBERNETES_ARGV_FONT_NAME) == 0)
     45        guac_terminal_apply_font(terminal, value, -1, 0);
     46
     47    /* Update only if font size is sane */
     48    else if (strcmp(name, GUAC_KUBERNETES_ARGV_FONT_SIZE) == 0) {
     49        int size = atoi(value);
     50        if (size > 0)
     51            guac_terminal_apply_font(terminal, NULL, size,
     52                    kubernetes_client->settings->resolution);
     53    }
     54
     55    /* Update Kubernetes terminal size */
     56    guac_kubernetes_resize(client,
     57            guac_terminal_get_rows(terminal),
     58            guac_terminal_get_columns(terminal));
     59
     60    return 0;
     61
     62}
     63
     64void* guac_kubernetes_send_current_argv(guac_user* user, void* data) {
     65
     66    /* Defer to the batch handler, using the user socket */
     67    return guac_kubernetes_send_current_argv_batch(user->client, user->socket);
     68
     69}
     70
     71void* guac_kubernetes_send_current_argv_batch(
     72        guac_client* client, guac_socket* socket) {
     73
     74    guac_kubernetes_client* kubernetes_client = (guac_kubernetes_client*) client->data;
     75    guac_terminal* terminal = kubernetes_client->term;
     76
     77    /* Send current color scheme */
     78    guac_client_stream_argv(client, socket, "text/plain",
     79            GUAC_KUBERNETES_ARGV_COLOR_SCHEME,
     80            guac_terminal_get_color_scheme(terminal));
     81
     82    /* Send current font name */
     83    guac_client_stream_argv(client, socket, "text/plain",
     84            GUAC_KUBERNETES_ARGV_FONT_NAME,
     85            guac_terminal_get_font_name(terminal));
     86
     87    /* Send current font size */
     88    char font_size[64];
     89    sprintf(font_size, "%i", guac_terminal_get_font_size(terminal));
     90    guac_client_stream_argv(client, socket, "text/plain",
     91            GUAC_KUBERNETES_ARGV_FONT_SIZE, font_size);
     92
     93    return NULL;
     94
     95}