cscg24-guacamole

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

io.h (4292B)


      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 GUAC_KUBERNETES_IO_H
     21#define GUAC_KUBERNETES_IO_H
     22
     23#include <guacamole/client.h>
     24#include <libwebsockets.h>
     25
     26#include <stdbool.h>
     27#include <stdint.h>
     28
     29/**
     30 * The maximum amount of data to include in any particular WebSocket message
     31 * to Kubernetes. This excludes the storage space required for the channel
     32 * index.
     33 */
     34#define GUAC_KUBERNETES_MAX_MESSAGE_SIZE 1024
     35
     36/**
     37 * The index of the Kubernetes channel used for STDIN.
     38 */
     39#define GUAC_KUBERNETES_CHANNEL_STDIN 0
     40
     41/**
     42 * The index of the Kubernetes channel used for STDOUT.
     43 */
     44#define GUAC_KUBERNETES_CHANNEL_STDOUT 1
     45
     46/**
     47 * The index of the Kubernetes channel used for STDERR.
     48 */
     49#define GUAC_KUBERNETES_CHANNEL_STDERR 2
     50
     51/**
     52 * The index of the Kubernetes channel used for terminal resize messages.
     53 */
     54#define GUAC_KUBERNETES_CHANNEL_RESIZE 4
     55
     56/**
     57 * An outbound message to be received by Kubernetes over WebSocket.
     58 */
     59typedef struct guac_kubernetes_message {
     60
     61    /**
     62     * lws_write() requires leading padding of LWS_PRE bytes to provide
     63     * scratch space for WebSocket framing.
     64     */
     65    uint8_t _padding[LWS_PRE];
     66
     67    /**
     68     * The index of the channel receiving the data, such as
     69     * GUAC_KUBERNETES_CHANNEL_STDIN.
     70     */
     71    uint8_t channel;
     72
     73    /**
     74     * The data that should be sent to Kubernetes (along with the channel
     75     * index).
     76     */
     77    char data[GUAC_KUBERNETES_MAX_MESSAGE_SIZE];
     78
     79    /**
     80     * The length of the data to be sent, excluding the channel index.
     81     */
     82    int length;
     83
     84} guac_kubernetes_message;
     85
     86
     87/**
     88 * Handles data received from Kubernetes over WebSocket, decoding the channel
     89 * index of the received data and forwarding that data accordingly.
     90 *
     91 * @param client
     92 *     The guac_client associated with the connection to Kubernetes.
     93 *
     94 * @param buffer
     95 *     The data received from Kubernetes.
     96 *
     97 * @param length
     98 *     The size of the data received from Kubernetes, in bytes.
     99 */
    100void guac_kubernetes_receive_data(guac_client* client,
    101        const char* buffer, size_t length);
    102
    103/**
    104 * Requests that the given data be sent along the given channel to the
    105 * Kubernetes server when the WebSocket connection is next available for
    106 * writing. If the WebSocket connection has not been available for writing for
    107 * long enough that the outbound message buffer is full, the request to send
    108 * this particular message will be dropped.
    109 *
    110 * @param client
    111 *     The guac_client associated with the Kubernetes connection.
    112 *
    113 * @param channel
    114 *     The Kubernetes channel on which to send the message,
    115 *     such as GUAC_KUBERNETES_CHANNEL_STDIN.
    116 *
    117 * @param data
    118 *     A buffer containing the data to send.
    119 *
    120 * @param length
    121 *     The number of bytes to send.
    122 */
    123void guac_kubernetes_send_message(guac_client* client,
    124        int channel, const char* data, int length);
    125
    126/**
    127 * Writes the oldest pending message within the outbound message queue,
    128 * as scheduled with guac_kubernetes_send_message(), removing that message
    129 * from the queue. This function MAY NOT be invoked outside the libwebsockets
    130 * event callback and MUST only be invoked in the context of a
    131 * LWS_CALLBACK_CLIENT_WRITEABLE event. If no messages are pending, this
    132 * function has no effect.
    133 *
    134 * @param client
    135 *     The guac_client associated with the Kubernetes connection.
    136 *
    137 * @return
    138 *     true if messages still remain to be written within the outbound message
    139 *     queue, false otherwise.
    140 */
    141bool guac_kubernetes_write_pending_message(guac_client* client);
    142
    143#endif
    144