cscg24-guacamole

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

ttymode.c (1873B)


      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#include "ttymode.h"
     22
     23#include <stdarg.h>
     24#include <stdbool.h>
     25#include <stdlib.h>
     26#include <string.h>
     27
     28int guac_ssh_ttymodes_init(char opcode_array[], ...) {
     29
     30    /* Initialize the variable argument list. */
     31    va_list args;
     32    va_start(args, opcode_array);
     33
     34    /* Initialize array pointer and byte counter. */
     35    char *current = opcode_array;
     36
     37    /* Loop through variable argument list. */
     38    while (true) {
     39       
     40        /* Next argument should be an opcode. */
     41        char opcode = (char)va_arg(args, int);
     42        *(current++) = opcode;
     43
     44        /* If it's the end opcode, we're done. */
     45        if (opcode == GUAC_SSH_TTY_OP_END)
     46            break;
     47
     48        /* Next argument should be 4-byte value. */
     49        uint32_t value = va_arg(args, uint32_t);
     50        *(current++) = (value >> 24) & 0xFF;
     51        *(current++) = (value >> 16) & 0xFF;
     52        *(current++) = (value >> 8) & 0xFF;
     53        *(current++) = value & 0xFF;
     54    }
     55
     56    /* We're done processing arguments. */
     57    va_end(args);
     58
     59    return current - opcode_array;
     60
     61}