cscg24-guacamole

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

user.c (3589B)


      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 "clipboard.h"
     23#include "input.h"
     24#include "common/display.h"
     25#include "common/dot_cursor.h"
     26#include "common/pointer_cursor.h"
     27#include "user.h"
     28#include "sftp.h"
     29#include "vnc.h"
     30
     31#ifdef ENABLE_PULSE
     32#include "pulse/pulse.h"
     33#endif
     34
     35#include <guacamole/argv.h>
     36#include <guacamole/audio.h>
     37#include <guacamole/client.h>
     38#include <guacamole/socket.h>
     39#include <guacamole/user.h>
     40#include <rfb/rfbclient.h>
     41#include <rfb/rfbproto.h>
     42
     43#include <pthread.h>
     44
     45int guac_vnc_user_join_handler(guac_user* user, int argc, char** argv) {
     46
     47    guac_vnc_client* vnc_client = (guac_vnc_client*) user->client->data;
     48
     49    /* Parse provided arguments */
     50    guac_vnc_settings* settings = guac_vnc_parse_args(user,
     51            argc, (const char**) argv);
     52
     53    /* Fail if settings cannot be parsed */
     54    if (settings == NULL) {
     55        guac_user_log(user, GUAC_LOG_INFO,
     56                "Badly formatted client arguments.");
     57        return 1;
     58    }
     59
     60    /* Store settings at user level */
     61    user->data = settings;
     62
     63    /* Connect via VNC if owner */
     64    if (user->owner) {
     65
     66        /* Store owner's settings at client level */
     67        vnc_client->settings = settings;
     68
     69        /* Start client thread */
     70        if (pthread_create(&vnc_client->client_thread, NULL, guac_vnc_client_thread, user->client)) {
     71            guac_user_log(user, GUAC_LOG_ERROR, "Unable to start VNC client thread.");
     72            return 1;
     73        }
     74
     75    }
     76
     77    /* Only handle events if not read-only */
     78    if (!settings->read_only) {
     79
     80        /* General mouse/keyboard events */
     81        user->mouse_handler = guac_vnc_user_mouse_handler;
     82        user->key_handler = guac_vnc_user_key_handler;
     83
     84        /* Inbound (client to server) clipboard transfer */
     85        if (!settings->disable_paste)
     86            user->clipboard_handler = guac_vnc_clipboard_handler;
     87        
     88        /* Updates to connection parameters if we own the connection */
     89        if (user->owner)
     90            user->argv_handler = guac_argv_handler;
     91
     92#ifdef ENABLE_COMMON_SSH
     93        /* Set generic (non-filesystem) file upload handler */
     94        if (settings->enable_sftp && !settings->sftp_disable_upload)
     95            user->file_handler = guac_vnc_sftp_file_handler;
     96#endif
     97
     98    }
     99
    100    return 0;
    101
    102}
    103
    104int guac_vnc_user_leave_handler(guac_user* user) {
    105
    106    guac_vnc_client* vnc_client = (guac_vnc_client*) user->client->data;
    107
    108    if (vnc_client->display) {
    109        /* Update shared cursor state */
    110        guac_common_cursor_remove_user(vnc_client->display->cursor, user);
    111    }
    112
    113    /* Free settings if not owner (owner settings will be freed with client) */
    114    if (!user->owner) {
    115        guac_vnc_settings* settings = (guac_vnc_settings*) user->data;
    116        guac_vnc_settings_free(settings);
    117    }
    118
    119    return 0;
    120}
    121