cscg24-guacamole

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

connection.h (3828B)


      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#ifndef GUACD_CONNECTION_H
     21#define GUACD_CONNECTION_H
     22
     23#include "config.h"
     24
     25#include "proc-map.h"
     26
     27#ifdef ENABLE_SSL
     28#include <openssl/ssl.h>
     29#endif
     30
     31/**
     32 * Parameters required by each connection thread.
     33 */
     34typedef struct guacd_connection_thread_params {
     35
     36    /**
     37     * The shared map of all connected clients.
     38     */
     39    guacd_proc_map* map;
     40
     41#ifdef ENABLE_SSL
     42    /**
     43     * SSL context for encrypted connections to guacd. If SSL is not active,
     44     * this will be NULL.
     45     */
     46    SSL_CTX* ssl_context;
     47#endif
     48
     49    /**
     50     * The file descriptor associated with the newly-accepted connection.
     51     */
     52    int connected_socket_fd;
     53
     54} guacd_connection_thread_params;
     55
     56/**
     57 * Handles an inbound connection to guacd, allowing guacd to continue listening
     58 * for other connections. The file descriptor of the inbound connection will
     59 * either be given to a new process for a new remote desktop connection, or
     60 * will be passed to an existing process for joining an existing remote desktop
     61 * connection. It is expected that this thread will operate detached. The
     62 * creating process need not join on the resulting thread.
     63 *
     64 * @param data
     65 *     A pointer to a guacd_connection_thread_params structure containing the
     66 *     shared overall map of currently-connected processes, the file
     67 *     descriptor associated with the newly-established connection that is to
     68 *     be either (1) associated with a new process or (2) passed on to an
     69 *     existing process, and the SSL context for the encryption surrounding
     70 *     that connection (if any).
     71 *
     72 * @return
     73 *     Always NULL.
     74 */
     75void* guacd_connection_thread(void* data);
     76
     77/**
     78 * Parameters required by the per-connection I/O transfer thread.
     79 */
     80typedef struct guacd_connection_io_thread_params {
     81
     82    /**
     83     * The guac_parser which may contain buffered, but unparsed, data from the
     84     * original guac_socket which must be transferred to the
     85     * connection-specific process.
     86     */
     87    guac_parser* parser;
     88
     89    /**
     90     * The guac_socket which is directly handling I/O from a user's connection
     91     * to guacd.
     92     */
     93    guac_socket* socket;
     94
     95    /**
     96     * The file descriptor which is being handled by a guac_socket within the
     97     * connection-specific process.
     98     */
     99    int fd;
    100
    101} guacd_connection_io_thread_params;
    102
    103/**
    104 * Transfers data back and forth between the guacd-side guac_socket and the
    105 * file descriptor used by the process-side guac_socket. Note that both the
    106 * provided guac_parser and the guac_socket will be freed once this thread
    107 * terminates, which will occur when no further data can be read from the
    108 * guac_socket.
    109 *
    110 * @param data
    111 *     A pointer to a guacd_connection_io_thread_params structure containing
    112 *     the guac_socket and file descriptor to transfer data between
    113 *     (bidirectionally), as well as the guac_parser associated with the
    114 *     guac_socket (which may have unhandled data in its parsing buffers).
    115 *
    116 * @return
    117 *     Always NULL.
    118 */
    119void* guacd_connection_io_thread(void* data);
    120
    121#endif
    122