cscg24-guacamole

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

input.c (3034B)


      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
     22#include "common/cursor.h"
     23#include "common/display.h"
     24#include "ssh.h"
     25#include "terminal/terminal.h"
     26
     27#include <guacamole/client.h>
     28#include <guacamole/recording.h>
     29#include <guacamole/user.h>
     30#include <libssh2.h>
     31
     32#include <pthread.h>
     33
     34int guac_ssh_user_mouse_handler(guac_user* user, int x, int y, int mask) {
     35
     36    guac_client* client = user->client;
     37    guac_ssh_client* ssh_client = (guac_ssh_client*) client->data;
     38    guac_terminal* term = ssh_client->term;
     39
     40    /* Skip if terminal not yet ready */
     41    if (term == NULL)
     42        return 0;
     43
     44    /* Report mouse position within recording */
     45    if (ssh_client->recording != NULL)
     46        guac_recording_report_mouse(ssh_client->recording, x, y, mask);
     47
     48    /* Send mouse event */
     49    guac_terminal_send_mouse(term, user, x, y, mask);
     50    return 0;
     51}
     52
     53int guac_ssh_user_key_handler(guac_user* user, int keysym, int pressed) {
     54
     55    guac_client* client = user->client;
     56    guac_ssh_client* ssh_client = (guac_ssh_client*) client->data;
     57    guac_terminal* term = ssh_client->term;
     58
     59    /* Report key state within recording */
     60    if (ssh_client->recording != NULL)
     61        guac_recording_report_key(ssh_client->recording,
     62                keysym, pressed);
     63
     64    /* Skip if terminal not yet ready */
     65    if (term == NULL)
     66        return 0;
     67
     68    /* Send key */
     69    guac_terminal_send_key(term, keysym, pressed);
     70    return 0;
     71}
     72
     73int guac_ssh_user_size_handler(guac_user* user, int width, int height) {
     74
     75    /* Get terminal */
     76    guac_client* client = user->client;
     77    guac_ssh_client* ssh_client = (guac_ssh_client*) client->data;
     78    guac_terminal* terminal = ssh_client->term;
     79
     80    /* Skip if terminal not yet ready */
     81    if (terminal == NULL)
     82        return 0;
     83
     84    /* Resize terminal */
     85    guac_terminal_resize(terminal, width, height);
     86
     87    /* Update SSH pty size if connected */
     88    if (ssh_client->term_channel != NULL) {
     89        pthread_mutex_lock(&(ssh_client->term_channel_lock));
     90        libssh2_channel_request_pty_size(ssh_client->term_channel,
     91                guac_terminal_get_columns(terminal),
     92                guac_terminal_get_rows(terminal));
     93        pthread_mutex_unlock(&(ssh_client->term_channel_lock));
     94    }
     95
     96    return 0;
     97}
     98