cscg24-guacamole

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

user-handlers.h (10735B)


      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
     21#ifndef _GUAC_USER_HANDLERS__H
     22#define _GUAC_USER_HANDLERS__H
     23
     24/**
     25 * Provides initial handler functions and a lookup structure for automatically
     26 * handling instructions received from each user. This is used only internally
     27 * within libguac, and is not installed along with the library.
     28 *
     29 * @file user-handlers.h
     30 */
     31
     32#include "config.h"
     33
     34#include "guacamole/client.h"
     35#include "guacamole/timestamp.h"
     36
     37/**
     38 * Internal handler for Guacamole instructions. Instruction handlers will be
     39 * invoked when their corresponding instructions are received. The mapping
     40 * of instruction opcode to handler is defined by the
     41 * __guac_instruction_handler_map array.
     42 *
     43 * @param user
     44 *     The user that sent the instruction.
     45 *
     46 * @param argc
     47 *     The number of arguments in argv.
     48 *
     49 * @param argv
     50 *     The arguments included with the instruction, excluding the opcode.
     51 *
     52 * @return
     53 *     Zero if the instruction was successfully handled, non-zero otherwise.
     54 */
     55typedef int __guac_instruction_handler(guac_user* user, int argc, char** argv);
     56
     57/**
     58 * Structure mapping an instruction opcode to an instruction handler.
     59 */
     60typedef struct __guac_instruction_handler_mapping {
     61
     62    /**
     63     * The instruction opcode which maps to a specific handler.
     64     */
     65    char* opcode;
     66
     67    /**
     68     * The handler which maps to a specific opcode.
     69     */
     70    __guac_instruction_handler* handler;
     71
     72} __guac_instruction_handler_mapping;
     73
     74/**
     75 * Internal initial handler for the sync instruction. When a sync instruction
     76 * is received, this handler will be called. Sync instructions are automatically
     77 * handled, thus there is no client handler for sync instruction.
     78 */
     79__guac_instruction_handler __guac_handle_sync;
     80
     81/**
     82 * Internal initial handler for the mouse instruction. When a mouse instruction
     83 * is received, this handler will be called. The client's mouse handler will
     84 * be invoked if defined.
     85 */
     86__guac_instruction_handler __guac_handle_mouse;
     87
     88/**
     89 * Internal initial handler for the touch instruction. When a touch instruction
     90 * is received, this handler will be called. The client's touch handler will
     91 * be invoked if defined.
     92 */
     93__guac_instruction_handler __guac_handle_touch;
     94
     95/**
     96 * Internal initial handler for the key instruction. When a key instruction
     97 * is received, this handler will be called. The client's key handler will
     98 * be invoked if defined.
     99 */
    100__guac_instruction_handler __guac_handle_key;
    101
    102/**
    103 * Internal initial handler for the audio instruction. When a audio
    104 * instruction is received, this handler will be called. The client's audio
    105 * handler will be invoked if defined.
    106 */
    107__guac_instruction_handler __guac_handle_audio;
    108
    109/**
    110 * Internal initial handler for the clipboard instruction. When a clipboard
    111 * instruction is received, this handler will be called. The client's clipboard
    112 * handler will be invoked if defined.
    113 */
    114__guac_instruction_handler __guac_handle_clipboard;
    115
    116/**
    117 * Internal initial handler for the file instruction. When a file instruction
    118 * is received, this handler will be called. The client's file handler will
    119 * be invoked if defined.
    120 */
    121__guac_instruction_handler __guac_handle_file;
    122
    123/**
    124 * Internal initial handler for the pipe instruction. When a pipe instruction
    125 * is received, this handler will be called. The client's pipe handler will
    126 * be invoked if defined.
    127 */
    128__guac_instruction_handler __guac_handle_pipe;
    129
    130/**
    131 * Internal initial handler for the argv instruction. When a argv instruction
    132 * is received, this handler will be called. The client's argv handler will
    133 * be invoked if defined.
    134 */
    135__guac_instruction_handler __guac_handle_argv;
    136
    137/**
    138 * Internal initial handler for the ack instruction. When a ack instruction
    139 * is received, this handler will be called. The client's ack handler will
    140 * be invoked if defined.
    141 */
    142__guac_instruction_handler __guac_handle_ack;
    143
    144/**
    145 * Internal initial handler for the blob instruction. When a blob instruction
    146 * is received, this handler will be called. The client's blob handler will
    147 * be invoked if defined.
    148 */
    149__guac_instruction_handler __guac_handle_blob;
    150
    151/**
    152 * Internal initial handler for the end instruction. When a end instruction
    153 * is received, this handler will be called. The client's end handler will
    154 * be invoked if defined.
    155 */
    156__guac_instruction_handler __guac_handle_end;
    157
    158/**
    159 * Internal initial handler for the get instruction. When a get instruction
    160 * is received, this handler will be called. The client's get handler will
    161 * be invoked if defined.
    162 */
    163__guac_instruction_handler __guac_handle_get;
    164
    165/**
    166 * Internal initial handler for the put instruction. When a put instruction
    167 * is received, this handler will be called. The client's put handler will
    168 * be invoked if defined.
    169 */
    170__guac_instruction_handler __guac_handle_put;
    171
    172/**
    173 * Internal initial handler for the size instruction. When a size instruction
    174 * is received, this handler will be called. The client's size handler will
    175 * be invoked if defined.
    176 */
    177__guac_instruction_handler __guac_handle_size;
    178
    179/**
    180 * Internal initial handler for the disconnect instruction. When a disconnect
    181 * instruction is received, this handler will be called. Disconnect
    182 * instructions are automatically handled, thus there is no client handler for
    183 * disconnect instruction.
    184 */
    185__guac_instruction_handler __guac_handle_disconnect;
    186
    187/**
    188 * Internal handler for the nop instruction.  This handler will be called when
    189 * the nop instruction is received, and will do nothing more than a TRACE level
    190 * log of the instruction.
    191 */
    192__guac_instruction_handler __guac_handle_nop;
    193
    194/**
    195 * Internal handler function that is called when the size instruction is
    196 * received during the handshake process.
    197 */
    198__guac_instruction_handler __guac_handshake_size_handler;
    199
    200/**
    201 * Internal handler function that is called when the audio instruction is
    202 * received during the handshake process, specifying the audio mimetypes
    203 * available to the client.
    204 */
    205__guac_instruction_handler __guac_handshake_audio_handler;
    206
    207/**
    208 * Internal handler function that is called when the video instruction is
    209 * received during the handshake process, specifying the video mimetypes
    210 * available to the client.
    211 */
    212__guac_instruction_handler __guac_handshake_video_handler;
    213
    214/**
    215 * Internal handler function that is called when the image instruction is
    216 * received during the handshake process, specifying the image mimetypes
    217 * available to the client.
    218 */
    219__guac_instruction_handler __guac_handshake_image_handler;
    220
    221/**
    222 * Internal handler function that is called when the name instruction is
    223 * received during the handshake process, specifying the name of the Guacamole
    224 * user establishing the connection.
    225 */
    226__guac_instruction_handler __guac_handshake_name_handler;
    227
    228/**
    229 * Internal handler function that is called when the timezone instruction is
    230 * received during the handshake process, specifying the timezone of the
    231 * client.
    232 */
    233__guac_instruction_handler __guac_handshake_timezone_handler;
    234
    235/**
    236 * Instruction handler mapping table. This is a NULL-terminated array of
    237 * __guac_instruction_handler_mapping structures, each mapping an opcode
    238 * to a __guac_instruction_handler. The end of the array must be marked
    239 * with a __guac_instruction_handler_mapping with the opcode set to
    240 * NULL (the NULL terminator).
    241 */
    242extern __guac_instruction_handler_mapping __guac_instruction_handler_map[];
    243
    244/**
    245 * Handler mapping table for instructions (opcodes) specifically for the
    246 * handshake portion of the connection.  Each
    247 * __guac_instruction_handler_mapping structure within this NULL-terminated
    248 * array maps an opcode to a __guac_instruction_handler.  The end of the array
    249 * must be marked with a mapping with the opcode set to NULL.
    250 */
    251extern __guac_instruction_handler_mapping __guac_handshake_handler_map[];
    252
    253/**
    254 * Frees the given array of mimetypes, including the space allocated to each
    255 * mimetype string within the array. The provided array of mimetypes MUST have
    256 * been allocated with guac_copy_mimetypes().
    257 *
    258 * @param mimetypes
    259 *     The NULL-terminated array of mimetypes to free. This array MUST have
    260 *     been previously allocated with guac_copy_mimetypes().
    261 */
    262void guac_free_mimetypes(char** mimetypes);
    263
    264/**
    265 * Copies the given array of mimetypes (strings) into a newly-allocated NULL-
    266 * terminated array of strings. Both the array and the strings within the array
    267 * are newly-allocated and must be later freed via guac_free_mimetypes().
    268 *
    269 * @param mimetypes
    270 *     The array of mimetypes to copy.
    271 *
    272 * @param count
    273 *     The number of mimetypes in the given array.
    274 *
    275 * @return
    276 *     A newly-allocated, NULL-terminated array containing newly-allocated
    277 *     copies of each of the mimetypes provided in the original mimetypes
    278 *     array.
    279 */
    280char** guac_copy_mimetypes(char** mimetypes, int count);
    281
    282/**
    283 * Call the appropriate handler defined by the given user for the given
    284 * instruction. A comparison is made between the instruction opcode and the
    285 * initial handler lookup table defined in the map that is provided to this
    286 * function. If an entry for the instruction is found in the provided map,
    287 * the handler defined in that map will be called and the value returned.  If
    288 * no match is found, it is silently ignored.
    289 *
    290 * @param map
    291 *     The array that holds the opcode to handler mappings.
    292 * 
    293 * @param user
    294 *     The user whose handlers should be called.
    295 *
    296 * @param opcode
    297 *     The opcode of the instruction to pass to the user via the appropriate
    298 *     handler.
    299 *
    300 * @param argc
    301 *     The number of arguments which are part of the instruction.
    302 *
    303 * @param argv
    304 *     An array of all arguments which are part of the instruction.
    305 *
    306 * @return
    307 *     Zero if the instruction was handled successfully, or non-zero otherwise.
    308 */
    309int __guac_user_call_opcode_handler(__guac_instruction_handler_mapping* map,
    310        guac_user* user, const char* opcode, int argc, char** argv);
    311
    312#endif