cscg24-guacamole

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

url.h (4351B)


      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_URL_H
     21#define GUAC_KUBERNETES_URL_H
     22
     23/**
     24 * The maximum number of characters allowed in the full path for any Kubernetes
     25 * endpoint.
     26 */
     27#define GUAC_KUBERNETES_MAX_ENDPOINT_LENGTH 1024
     28
     29/**
     30 * Escapes the given string such that it can be included safely within a URL.
     31 * This function duplicates the behavior of JavaScript's encodeURIComponent(),
     32 * escaping all but the following characters: A-Z a-z 0-9 - _ . ! ~ * ' ( )
     33 *
     34 * @param output
     35 *     The buffer which should receive the escaped string. This buffer may be
     36 *     touched even if escaping is unsuccessful.
     37 *
     38 * @param length
     39 *     The number of bytes available in the given output buffer.
     40 *
     41 * @param str
     42 *     The string to escape.
     43 *
     44 * @return
     45 *     Zero if the string was successfully escaped and written into the
     46 *     provided output buffer without being truncated, including null
     47 *     terminator, non-zero otherwise.
     48 */
     49int guac_kubernetes_escape_url_component(char* output, int length,
     50        const char* str);
     51
     52/**
     53 * Appends the given query parameter and value to the given buffer. If the
     54 * buffer does not already contain the '?' character denoting the start of the
     55 * query string, it will be added. If the buffer already contains a query
     56 * string, a '&' character will be added before the new parameter. The
     57 * parameter value will automatically be URL-escaped as necessary.
     58 *
     59 * @param buffer
     60 *     The buffer which should receive the parameter. It could contain the endpoint path.
     61 *     The parameter will be written to the end of the buffer.
     62 *
     63 * @param length
     64 *     The number of bytes available in the given buffer.
     65 *
     66 * @param param_name
     67 *     The name of the parameter. If the parameter name contains characters
     68 *     with special meaning to URLs, it must already be URL-escaped.
     69 *
     70 * @param param_value
     71 *     The value of the parameter.
     72 *
     73 * @return
     74 *     Zero if the parameter was successfully attached to the buffer,
     75 *     non-zero if insufficient space exists within the buffer or
     76 *     buffer not null terminated.
     77 */
     78int guac_kubernetes_append_endpoint_param(char* buffer, int length,
     79        const char* param_name, const char* param_value);
     80
     81/**
     82 * Generates the full path to the Kubernetes API endpoint which handles
     83 * attaching to running containers within specific pods. Values within the path
     84 * will be URL-escaped as necessary.
     85 *
     86 * @param buffer
     87 *     The buffer which should receive the endpoint path. This buffer may be
     88 *     touched even if the endpoint path could not be generated.
     89 *
     90 * @param length
     91 *     The number of bytes available in the given buffer.
     92 *
     93 * @param kubernetes_namespace
     94 *     The name of the Kubernetes namespace of the pod containing the container
     95 *     being attached to.
     96 *
     97 * @param kubernetes_pod
     98 *     The name of the Kubernetes pod containing with the container being
     99 *     attached to.
    100 *
    101 * @param kubernetes_container
    102 *     The name of the container to attach to, or NULL to arbitrarily attach
    103 *     to the first container in the pod.
    104 *  
    105 * @param exec_command
    106 *     The command used to run a new process and attach to it,
    107 *     instead of the main container process.
    108 *
    109 * @return
    110 *     Zero if the endpoint path was successfully written to the provided
    111 *     buffer, non-zero if insufficient space exists within the buffer.
    112 */
    113int guac_kubernetes_endpoint_uri(char* buffer, int length,
    114        const char* kubernetes_namespace, const char* kubernetes_pod,
    115        const char* kubernetes_container, const char* exec_command);
    116
    117#endif
    118