argv.c (3299B)
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 "telnet.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 <stdio.h> 30#include <stdlib.h> 31#include <string.h> 32 33int guac_telnet_argv_callback(guac_user* user, const char* mimetype, 34 const char* name, const char* value, void* data) { 35 36 guac_client* client = user->client; 37 guac_telnet_client* telnet_client = (guac_telnet_client*) client->data; 38 guac_terminal* terminal = telnet_client->term; 39 40 /* Update color scheme */ 41 if (strcmp(name, GUAC_TELNET_ARGV_COLOR_SCHEME) == 0) 42 guac_terminal_apply_color_scheme(terminal, value); 43 44 /* Update font name */ 45 else if (strcmp(name, GUAC_TELNET_ARGV_FONT_NAME) == 0) 46 guac_terminal_apply_font(terminal, value, -1, 0); 47 48 /* Update only if font size is sane */ 49 else if (strcmp(name, GUAC_TELNET_ARGV_FONT_SIZE) == 0) { 50 int size = atoi(value); 51 if (size > 0) 52 guac_terminal_apply_font(terminal, NULL, size, 53 telnet_client->settings->resolution); 54 } 55 56 /* Update terminal window size if connected */ 57 if (telnet_client->telnet != NULL && telnet_client->naws_enabled) 58 guac_telnet_send_naws(telnet_client->telnet, 59 guac_terminal_get_columns(terminal), 60 guac_terminal_get_rows(terminal)); 61 62 return 0; 63 64} 65 66void* guac_telnet_send_current_argv(guac_user* user, void* data) { 67 68 /* Defer to the batch handler, using the user's socket to send the data */ 69 guac_telnet_send_current_argv_batch(user->client, user->socket); 70 71 return NULL; 72 73} 74 75void guac_telnet_send_current_argv_batch( 76 guac_client* client, guac_socket* socket) { 77 78 guac_telnet_client* telnet_client = (guac_telnet_client*) client->data; 79 guac_terminal* terminal = telnet_client->term; 80 81 /* Send current color scheme */ 82 guac_client_stream_argv(client, socket, "text/plain", 83 GUAC_TELNET_ARGV_COLOR_SCHEME, 84 guac_terminal_get_color_scheme(terminal)); 85 86 /* Send current font name */ 87 guac_client_stream_argv(client, socket, "text/plain", 88 GUAC_TELNET_ARGV_FONT_NAME, 89 guac_terminal_get_font_name(terminal)); 90 91 /* Send current font size */ 92 char font_size[64]; 93 sprintf(font_size, "%i", guac_terminal_get_font_size(terminal)); 94 guac_client_stream_argv(client, socket, "text/plain", 95 GUAC_TELNET_ARGV_FONT_SIZE, font_size); 96 97} 98