cscg24-guacamole

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

user.c (3450B)


      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 "argv.h"
     23#include "clipboard.h"
     24#include "input.h"
     25#include "pipe.h"
     26#include "settings.h"
     27#include "telnet.h"
     28#include "terminal/terminal.h"
     29#include "user.h"
     30
     31#include <guacamole/client.h>
     32#include <guacamole/socket.h>
     33#include <guacamole/user.h>
     34
     35#include <pthread.h>
     36#include <string.h>
     37
     38int guac_telnet_user_join_handler(guac_user* user, int argc, char** argv) {
     39
     40    guac_client* client = user->client;
     41    guac_telnet_client* telnet_client = (guac_telnet_client*) client->data;
     42
     43    /* Parse provided arguments */
     44    guac_telnet_settings* settings = guac_telnet_parse_args(user,
     45            argc, (const char**) argv);
     46
     47    /* Fail if settings cannot be parsed */
     48    if (settings == NULL) {
     49        guac_user_log(user, GUAC_LOG_INFO,
     50                "Badly formatted client arguments.");
     51        return 1;
     52    }
     53
     54    /* Store settings at user level */
     55    user->data = settings;
     56
     57    /* Connect via telnet if owner */
     58    if (user->owner) {
     59
     60        /* Store owner's settings at client level */
     61        telnet_client->settings = settings;
     62
     63        /* Start client thread */
     64        if (pthread_create(&(telnet_client->client_thread), NULL,
     65                    guac_telnet_client_thread, (void*) client)) {
     66            guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR,
     67                    "Unable to start telnet client thread");
     68            return 1;
     69        }
     70
     71    }
     72
     73    /* Only handle events if not read-only */
     74    if (!settings->read_only) {
     75
     76        /* General mouse/keyboard events */
     77        user->key_handler = guac_telnet_user_key_handler;
     78        user->mouse_handler = guac_telnet_user_mouse_handler;
     79
     80        /* Inbound (client to server) clipboard transfer */
     81        if (!settings->disable_paste)
     82            user->clipboard_handler = guac_telnet_clipboard_handler;
     83
     84        /* STDIN redirection */
     85        user->pipe_handler = guac_telnet_pipe_handler;
     86
     87        /* Updates to connection parameters */
     88        user->argv_handler = guac_argv_handler;
     89
     90        /* Display size change events */
     91        user->size_handler = guac_telnet_user_size_handler;
     92
     93    }
     94
     95    return 0;
     96
     97}
     98
     99int guac_telnet_user_leave_handler(guac_user* user) {
    100
    101    guac_telnet_client* telnet_client =
    102        (guac_telnet_client*) user->client->data;
    103
    104    /* Remove the user from the terminal */
    105    guac_terminal_remove_user(telnet_client->term, user);
    106
    107    /* Free settings if not owner (owner settings will be freed with client) */
    108    if (!user->owner) {
    109        guac_telnet_settings* settings = (guac_telnet_settings*) user->data;
    110        guac_telnet_settings_free(settings);
    111    }
    112
    113    return 0;
    114}
    115