cscg24-guacamole

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

generate-entry-wrappers.pl (2818B)


      1#!/usr/bin/env perl
      2#
      3# Licensed to the Apache Software Foundation (ASF) under one
      4# or more contributor license agreements.  See the NOTICE file
      5# distributed with this work for additional information
      6# regarding copyright ownership.  The ASF licenses this file
      7# to you under the Apache License, Version 2.0 (the
      8# "License"); you may not use this file except in compliance
      9# with the License.  You may obtain a copy of the License at
     10#
     11#   http://www.apache.org/licenses/LICENSE-2.0
     12#
     13# Unless required by applicable law or agreed to in writing,
     14# software distributed under the License is distributed on an
     15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     16# KIND, either express or implied.  See the License for the
     17# specific language governing permissions and limitations
     18# under the License.
     19#
     20
     21#
     22# generate-entry-wrappers.pl
     23#
     24# Generates C source which defines wrapper functions for FreeRDP plugin entry
     25# points, allowing multiple instances of the same plugin to be loaded despite
     26# otherwise always having the same entry point.
     27#
     28# The resulting source is stored within "_generated_channel_entry_wrappers.c".
     29#
     30
     31use strict;
     32
     33##
     34## The maximum number of static channels supported by Guacamole's RDP support.
     35##
     36my $GUAC_RDP_MAX_CHANNELS;
     37
     38# Extract value of GUAC_RDP_MAX_CHANNELS macro from provided source
     39while (<>) {
     40    if ((my $value) = m/^\s*#define\s+GUAC_RDP_MAX_CHANNELS\s+(\d+)\s*$/) {
     41        $GUAC_RDP_MAX_CHANNELS = $value;
     42    }
     43}
     44
     45open OUTPUT, ">", "_generated_channel_entry_wrappers.c";
     46
     47# Generate required headers
     48print OUTPUT <<"EOF";
     49#include "plugins/channels.h"
     50#include <freerdp/channels/channels.h>
     51#include <freerdp/freerdp.h>
     52EOF
     53
     54# Generate wrapper definitions for PVIRTUALCHANNELENTRYEX entry point variant
     55print OUTPUT <<"EOF" for (1..$GUAC_RDP_MAX_CHANNELS);
     56static BOOL guac_rdp_plugin_entry_ex_wrapper$_(PCHANNEL_ENTRY_POINTS_EX entry_points_ex, PVOID init_handle) {
     57    return guac_rdp_wrapped_entry_ex[$_ - 1](entry_points_ex, init_handle);
     58}
     59EOF
     60
     61# Generate wrapper definitions for PVIRTUALCHANNELENTRY entry point variant
     62print OUTPUT <<"EOF" for (1..$GUAC_RDP_MAX_CHANNELS);
     63static BOOL guac_rdp_plugin_entry_wrapper$_(PCHANNEL_ENTRY_POINTS entry_points) {
     64    return guac_rdp_wrapped_entry[$_ - 1](entry_points);
     65}
     66EOF
     67
     68# Populate lookup table of PVIRTUALCHANNELENTRYEX wrapper functions
     69print OUTPUT "PVIRTUALCHANNELENTRYEX guac_rdp_entry_ex_wrappers[$GUAC_RDP_MAX_CHANNELS] = {\n";
     70print OUTPUT "    guac_rdp_plugin_entry_ex_wrapper$_,\n" for (1..$GUAC_RDP_MAX_CHANNELS);
     71print OUTPUT "};\n";
     72
     73# Populate lookup table of PVIRTUALCHANNELENTRY wrapper functions
     74print OUTPUT "PVIRTUALCHANNELENTRY guac_rdp_entry_wrappers[$GUAC_RDP_MAX_CHANNELS] = {\n";
     75print OUTPUT "    guac_rdp_plugin_entry_wrapper$_,\n" for (1..$GUAC_RDP_MAX_CHANNELS);
     76print OUTPUT "};\n";
     77