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