From 30515fe4ecc538dcbfb5422ccef6ada9146ad13d Mon Sep 17 00:00:00 2001 From: Matthew McClaskey Date: Mon, 4 Nov 2024 09:25:22 +0000 Subject: [PATCH 001/167] KASM-5095 update logo and docs link --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5efc230..ae9ceb5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # KasmVNC - Linux Web Remote Desktop - + KasmVNC provides remote web-based access to a Desktop or application. While VNC is in the name, KasmVNC differs from other VNC variants such as TigerVNC, RealVNC, and TurboVNC. KasmVNC has broken from the RFB specification which defines VNC, in order to support modern technologies and increase security. KasmVNC is accessed by users from any modern browser and does not support legacy VNC viewer applications. KasmVNC uses a modern YAML based configuration at the server and user level, allowing for ease of management. @@ -10,7 +10,7 @@ KasmVNC provides remote web-based access to a Desktop or application. While VNC **Do not use the README from the master branch**, unless you are compiling KasmVNC yourself from the tip of master. Use the documentation for your specific release. - - [KasmVNC 1.0.0 Documentation](https://www.kasmweb.com/kasmvnc/docs/1.0.0/index.html) + - [KasmVNC Documentation](https://www.kasmweb.com/kasmvnc/docs/latest/index.html) For beta releases prior to version 1.0.0, use the README in this github project on the tagged commit for that release. From f88bcd573b165e0e2d149bdfadd19e7ad7b06afc Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Tue, 28 Jan 2025 12:16:00 +1300 Subject: [PATCH 002/167] Debian: add missing dependency on libdatetime-perl --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index bff5f2a..11fac2f 100644 --- a/debian/control +++ b/debian/control @@ -14,7 +14,7 @@ Architecture: amd64 arm64 Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends}, ssl-cert, xauth, x11-xkb-utils, xkb-data, procps, libswitch-perl, libyaml-tiny-perl, libhash-merge-simple-perl, libscalar-list-utils-perl, liblist-moreutils-perl, - libtry-tiny-perl, libdatetime-timezone-perl, libgbm1 + libtry-tiny-perl, libdatetime-perl, libdatetime-timezone-perl, libgbm1 Provides: vnc-server Description: KasmVNC provides remote web-based access to a Desktop or application. While VNC is in the name, KasmVNC differs from other VNC variants such From 0b701e6c18ac78d2344578335e3be8dac3a7c0c8 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 31 Jan 2025 17:54:05 +1300 Subject: [PATCH 003/167] KASM-6518 Remove Bionic support --- .gitlab-ci.yml | 54 +++----------------- builder/README.md | 11 ++--- builder/dockerfile.ubuntu_bionic.build | 32 ------------ builder/dockerfile.ubuntu_bionic.deb.build | 17 ------- builder/dockerfile.ubuntu_bionic.deb.test | 57 ---------------------- builder/dockerfile.ubuntu_bionic.test | 51 ------------------- builder/dockerfile.ubuntu_focal.deb.test | 2 +- builder/dockerfile.ubuntu_jammy.deb.test | 2 +- builder/os_ver_cli.sh | 2 +- 9 files changed, 16 insertions(+), 212 deletions(-) delete mode 100644 builder/dockerfile.ubuntu_bionic.build delete mode 100644 builder/dockerfile.ubuntu_bionic.deb.build delete mode 100644 builder/dockerfile.ubuntu_bionic.deb.test delete mode 100644 builder/dockerfile.ubuntu_bionic.test diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6dd1bf6..73fec9a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,7 +7,7 @@ variables: GITLAB_SHARED_DIND_DIR: /builds/$CI_PROJECT_PATH/shared GIT_SUBMODULE_STRATEGY: normal GIT_FETCH_EXTRA_FLAGS: --tags --force - # E.g. BUILD_JOBS: build_debian_buster,build_ubuntu_bionic. This will include + # E.g. BUILD_JOBS: build_debian_buster,build_ubuntu_focal. This will include # arm builds, because build_debian_buster_arm matches build_debian_buster. # "BUILD_JOBS: none" won't build any build jobs, nor www. BUILD_JOBS: all @@ -66,44 +66,6 @@ build_www: paths: - output/ -build_ubuntu_bionic: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package ubuntu bionic - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_ubuntu_bionic_arm: - stage: build - allow_failure: false - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package ubuntu bionic - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - build_ubuntu_focal: stage: build allow_failure: true @@ -198,7 +160,7 @@ build_ubuntu_noble: artifacts: paths: - output/ - + build_ubuntu_noble_arm: stage: build allow_failure: true @@ -209,7 +171,7 @@ build_ubuntu_noble_arm: - *prepare_www after_script: - *prepare_artfacts - script: + script: - bash builder/build-package ubuntu noble; only: variables: @@ -617,13 +579,13 @@ build_fedora_forty: artifacts: paths: - output/ - + build_fedora_forty_arm: stage: build allow_failure: true tags: - oci-fixed-arm - before_script: + before_script: - *prepare_build - *prepare_www after_script: @@ -655,18 +617,18 @@ build_fedora_fortyone: artifacts: paths: - output/ - + build_fedora_fortyone_arm: stage: build allow_failure: true tags: - oci-fixed-arm - before_script: + before_script: - *prepare_build - *prepare_www after_script: - *prepare_artfacts - script: + script: - bash builder/build-package fedora fortyone; only: variables: diff --git a/builder/README.md b/builder/README.md index ea05cc1..b5f5276 100644 --- a/builder/README.md +++ b/builder/README.md @@ -7,7 +7,7 @@ Docker CE # os_codename is what "lsb_release -c" outputs, e.g. buster, focal. # # build_tag allows building multiple versions of deb package (rpm not supported) -# targeting a single distro release (e.g. Ubuntu Bionic). If build_tag is given, +# targeting a single distro release (e.g. Ubuntu Focal). If build_tag is given, # the package name will include build_tag as part of Debian revision. For # example: # * with build_tag: kasmvncserver_0.9.1~beta-1+libjpeg-turbo-latest_amd64.deb @@ -16,7 +16,6 @@ Docker CE # # Packages will be placed under builder/build/ -builder/build-package ubuntu bionic builder/build-package ubuntu focal builder/build-package debian buster builder/build-package debian bullseye @@ -118,7 +117,7 @@ locally by doing stuff like this: ``` bash -c ' . .ci/upload.sh; -prepare_upload_filename "bionic/kasmvncserver_0.9.1~beta-1+libjpeg-turbo-latest_amd64.deb"; +prepare_upload_filename "focal/kasmvncserver_0.9.1~beta-1+libjpeg-turbo-latest_amd64.deb"; echo $upload_filename;' ``` @@ -178,7 +177,7 @@ These instructions assume KasmVNC has been cloned at $HOME and ```kasm_www.tar.g cd ~ tar -zxf kasm_www.tar.gz -C KasmVNC/builder/ cd KasmVNC -sudo builder/build-package ubuntu bionic +sudo builder/build-package ubuntu focal ``` -The resulting deb package can be found under ~/KasmVNC/builder/build/bionic -Replace ```bionic``` with ```focal``` to build for Ubuntu 20.04LTS. At this time, only Ubuntu Bionic has been tested, however, other Debian based builds we support should also work. +The resulting deb package can be found under ~/KasmVNC/builder/build/focal +Replace ```focal``` with ```noble``` to build for Ubuntu 24.04LTS. diff --git a/builder/dockerfile.ubuntu_bionic.build b/builder/dockerfile.ubuntu_bionic.build deleted file mode 100644 index c76b4eb..0000000 --- a/builder/dockerfile.ubuntu_bionic.build +++ /dev/null @@ -1,32 +0,0 @@ -FROM ubuntu:18.04 - -ENV KASMVNC_BUILD_OS ubuntu -ENV KASMVNC_BUILD_OS_CODENAME bionic -ENV XORG_VER 1.20.10 - -RUN sed -i 's$# deb-src$deb-src$' /etc/apt/sources.list - -RUN apt-get update && \ - apt-get -y install sudo - -RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev -RUN apt-get update && apt-get -y install cmake git libgnutls28-dev vim wget tightvncserver curl -RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev - -ENV SCRIPTS_DIR=/tmp/scripts -COPY builder/scripts $SCRIPTS_DIR -RUN $SCRIPTS_DIR/build-webp -RUN $SCRIPTS_DIR/build-libjpeg-turbo - -# Fix for older required libs -#RUN cd /tmp && wget http://launchpadlibrarian.net/347526424/libxfont1-dev_1.5.2-4ubuntu2_amd64.deb && \ -# wget http://launchpadlibrarian.net/347526425/libxfont1_1.5.2-4ubuntu2_amd64.deb && \ -# dpkg -i libxfont1_1.5.2-4ubuntu2_amd64.deb && \ -# dpkg -i libxfont1-dev_1.5.2-4ubuntu2_amd64.deb - -RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo - -COPY --chown=docker:docker . /src/ - -USER docker -ENTRYPOINT ["/src/builder/build.sh"] diff --git a/builder/dockerfile.ubuntu_bionic.deb.build b/builder/dockerfile.ubuntu_bionic.deb.build deleted file mode 100644 index a554ecb..0000000 --- a/builder/dockerfile.ubuntu_bionic.deb.build +++ /dev/null @@ -1,17 +0,0 @@ -FROM ubuntu:bionic - -RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs - -# Install build-deps for the package. -COPY ./debian/control /tmp -RUN apt-get update && echo YYY | mk-build-deps --install --remove /tmp/control - -ARG L_UID -RUN if [ "$L_UID" -eq 0 ]; then \ - useradd -m docker; \ - else \ - useradd -m docker -u $L_UID;\ - fi - -USER docker diff --git a/builder/dockerfile.ubuntu_bionic.deb.test b/builder/dockerfile.ubuntu_bionic.deb.test deleted file mode 100644 index 8d68055..0000000 --- a/builder/dockerfile.ubuntu_bionic.deb.test +++ /dev/null @@ -1,57 +0,0 @@ -FROM ubuntu:bionic - -ENV DISPLAY=:1 \ - VNC_PORT=8443 \ - VNC_RESOLUTION=1280x720 \ - MAX_FRAME_RATE=24 \ - VNCOPTIONS="-PreferBandwidth -DynamicQualityMin=4 -DynamicQualityMax=7" \ - HOME=/home/user \ - TERM=xterm \ - STARTUPDIR=/dockerstartup \ - INST_SCRIPTS=/dockerstartup/install \ - KASM_RX_HOME=/dockerstartup/kasmrx \ - DEBIAN_FRONTEND=noninteractive \ - VNC_COL_DEPTH=24 \ - VNC_RESOLUTION=1280x1024 \ - VNC_PW=vncpassword \ - VNC_USER=user \ - VNC_VIEW_ONLY_PW=vncviewonlypassword \ - LD_LIBRARY_PATH=/usr/local/lib/ \ - OMP_WAIT_POLICY=PASSIVE \ - SHELL=/bin/bash \ - SINGLE_APPLICATION=0 \ - KASMVNC_BUILD_OS=ubuntu \ - KASMVNC_BUILD_OS_CODENAME=bionic - -EXPOSE $VNC_PORT - -WORKDIR $HOME - -### REQUIRED STUFF ### - -RUN apt-get update && apt-get install -y supervisor xfce4 xfce4-terminal xterm libnss-wrapper gettext wget -RUN apt-get purge -y pm-utils xscreensaver* -RUN apt-get update && apt-get install -y vim less -RUN apt-get update && apt-get -y install lsb-release - -RUN echo 'source $STARTUPDIR/generate_container_user' >> $HOME/.bashrc - -RUN mkdir -p $STARTUPDIR -COPY builder/startup/ $STARTUPDIR - -### START CUSTOM STUFF #### - -COPY ./builder/scripts/ /tmp/scripts/ -COPY ./debian/changelog /tmp - -ARG KASMVNC_PACKAGE_DIR -COPY $KASMVNC_PACKAGE_DIR/kasmvncserver_*.deb /tmp/ -RUN /tmp/scripts/install_kasmvncserver_package - -### END CUSTOM STUFF ### - -RUN chown -R 1000:0 $HOME -USER 1000:ssl-cert -WORKDIR $HOME - -ENTRYPOINT [ "/dockerstartup/vnc_startup.sh" ] diff --git a/builder/dockerfile.ubuntu_bionic.test b/builder/dockerfile.ubuntu_bionic.test deleted file mode 100644 index a9c2049..0000000 --- a/builder/dockerfile.ubuntu_bionic.test +++ /dev/null @@ -1,51 +0,0 @@ -FROM ubuntu:18.04 - -ENV DISPLAY=:1 \ - VNC_PORT=8443 \ - VNC_RESOLUTION=1280x720 \ - MAX_FRAME_RATE=24 \ - VNCOPTIONS="-PreferBandwidth -DynamicQualityMin=4 -DynamicQualityMax=7" \ - HOME=/home/user \ - TERM=xterm \ - STARTUPDIR=/dockerstartup \ - INST_SCRIPTS=/dockerstartup/install \ - KASM_RX_HOME=/dockerstartup/kasmrx \ - DEBIAN_FRONTEND=noninteractive \ - VNC_COL_DEPTH=24 \ - VNC_RESOLUTION=1280x1024 \ - VNC_PW=vncpassword \ - VNC_USER=user \ - VNC_VIEW_ONLY_PW=vncviewonlypassword \ - LD_LIBRARY_PATH=/usr/local/lib/ \ - OMP_WAIT_POLICY=PASSIVE \ - SHELL=/bin/bash \ - SINGLE_APPLICATION=0 \ - KASMVNC_BUILD_OS=ubuntu \ - KASMVNC_BUILD_OS_CODENAME=bionic - -EXPOSE $VNC_PORT - -WORKDIR $HOME - -### REQUIRED STUFF ### - -RUN apt-get update && apt-get install -y supervisor xfce4 xfce4-terminal xterm libnss-wrapper gettext wget -RUN apt-get purge -y pm-utils xscreensaver* - -RUN echo 'source $STARTUPDIR/generate_container_user' >> $HOME/.bashrc - -RUN mkdir -p $STARTUPDIR -COPY builder/startup/ $STARTUPDIR - -### START CUSTOM STUFF #### - -COPY build/kasmvnc.${KASMVNC_BUILD_OS}_${KASMVNC_BUILD_OS_CODENAME}.tar.gz /tmp/ -RUN tar -xzvf /tmp/kasmvnc.${KASMVNC_BUILD_OS}_${KASMVNC_BUILD_OS_CODENAME}.tar.gz --strip 1 -C / - -### END CUSTOM STUFF ### - -RUN chown -R 1000:0 $HOME -USER 1000 -WORKDIR $HOME - -ENTRYPOINT [ "/dockerstartup/vnc_startup.sh" ] diff --git a/builder/dockerfile.ubuntu_focal.deb.test b/builder/dockerfile.ubuntu_focal.deb.test index 16cd8a0..1ee3ad0 100644 --- a/builder/dockerfile.ubuntu_focal.deb.test +++ b/builder/dockerfile.ubuntu_focal.deb.test @@ -21,7 +21,7 @@ ENV DISPLAY=:1 \ SHELL=/bin/bash \ SINGLE_APPLICATION=0 \ KASMVNC_BUILD_OS=ubuntu \ - KASMVNC_BUILD_OS_CODENAME=bionic + KASMVNC_BUILD_OS_CODENAME=focal EXPOSE $VNC_PORT diff --git a/builder/dockerfile.ubuntu_jammy.deb.test b/builder/dockerfile.ubuntu_jammy.deb.test index 4e5f0dd..831a7c8 100644 --- a/builder/dockerfile.ubuntu_jammy.deb.test +++ b/builder/dockerfile.ubuntu_jammy.deb.test @@ -21,7 +21,7 @@ ENV DISPLAY=:1 \ SHELL=/bin/bash \ SINGLE_APPLICATION=0 \ KASMVNC_BUILD_OS=ubuntu \ - KASMVNC_BUILD_OS_CODENAME=bionic + KASMVNC_BUILD_OS_CODENAME=jammy EXPOSE $VNC_PORT diff --git a/builder/os_ver_cli.sh b/builder/os_ver_cli.sh index 534810d..cc19427 100644 --- a/builder/os_ver_cli.sh +++ b/builder/os_ver_cli.sh @@ -1,7 +1,7 @@ #!/bin/bash default_os=${default_os:-ubuntu} -default_os_codename=${default_os_codename:-bionic} +default_os_codename=${default_os_codename:-noble} os=${1:-$default_os} os_codename=${2:-$default_os_codename} From 18bb21671e140348bba08f5d14dd35360b91ae55 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 31 Jan 2025 18:02:45 +1300 Subject: [PATCH 004/167] KASM-6518 Remove support for Alpine 3.17 --- .gitlab-ci.yml | 37 ----------- builder/dockerfile.alpine_317.apk.build | 7 --- builder/dockerfile.alpine_317.build | 82 ------------------------- 3 files changed, 126 deletions(-) delete mode 100644 builder/dockerfile.alpine_317.apk.build delete mode 100644 builder/dockerfile.alpine_317.build diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 73fec9a..295c93b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -637,43 +637,6 @@ build_fedora_fortyone_arm: paths: - output/ -build_alpine_317: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 317; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_317_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 317; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ test: stage: test diff --git a/builder/dockerfile.alpine_317.apk.build b/builder/dockerfile.alpine_317.apk.build deleted file mode 100644 index 732f5f0..0000000 --- a/builder/dockerfile.alpine_317.apk.build +++ /dev/null @@ -1,7 +0,0 @@ -FROM alpine:3.17 - -RUN apk add shadow bash - -RUN useradd -m docker && echo "docker:docker" | chpasswd - -USER docker diff --git a/builder/dockerfile.alpine_317.build b/builder/dockerfile.alpine_317.build deleted file mode 100644 index 0b23bcb..0000000 --- a/builder/dockerfile.alpine_317.build +++ /dev/null @@ -1,82 +0,0 @@ -FROM alpine:3.17 - -ENV KASMVNC_BUILD_OS alpine -ENV KASMVNC_BUILD_OS_CODENAME 317 -ENV XORG_VER 21.1.8 - -RUN \ - echo "**** install build deps ****" && \ - apk add \ - alpine-release \ - alpine-sdk \ - autoconf \ - automake \ - bash \ - ca-certificates \ - cmake \ - coreutils \ - curl \ - eudev-dev \ - font-cursor-misc \ - font-misc-misc \ - font-util-dev \ - git \ - grep \ - jq \ - libdrm-dev \ - libepoxy-dev \ - libjpeg-turbo-dev \ - libjpeg-turbo-static \ - libpciaccess-dev \ - libtool \ - libwebp-dev \ - libx11-dev \ - libxau-dev \ - libxcb-dev \ - libxcursor-dev \ - libxcvt-dev \ - libxdmcp-dev \ - libxext-dev \ - libxfont2-dev \ - libxkbfile-dev \ - libxrandr-dev \ - libxshmfence-dev \ - libxtst-dev \ - mesa-dev \ - mesa-dri-gallium \ - meson \ - nettle-dev \ - openssl-dev \ - pixman-dev \ - procps \ - shadow \ - tar \ - tzdata \ - wayland-dev \ - wayland-protocols \ - xcb-util-dev \ - xcb-util-image-dev \ - xcb-util-keysyms-dev \ - xcb-util-renderutil-dev \ - xcb-util-wm-dev \ - xinit \ - xkbcomp \ - xkbcomp-dev \ - xkeyboard-config \ - xorgproto \ - xorg-server-common \ - xorg-server-dev \ - xtrans - - -ENV SCRIPTS_DIR=/tmp/scripts -COPY builder/scripts $SCRIPTS_DIR -RUN $SCRIPTS_DIR/build-webp -RUN $SCRIPTS_DIR/build-libjpeg-turbo - -RUN useradd -m docker && echo "docker:docker" | chpasswd - -COPY --chown=docker:docker . /src/ - -USER docker -ENTRYPOINT ["/src/builder/build.sh"] From 0eba021bde01240edefde0d42150f43e19147c74 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 31 Jan 2025 18:22:01 +1300 Subject: [PATCH 005/167] KASM-6518 Remove CentOS support --- BUILDING.txt | 14 +- README.md | 18 +- builder/README.md | 3 +- builder/build.sh | 12 -- builder/bump-package-version-rpm | 2 +- .../dockerfile.centos_core.barebones.rpm.test | 20 --- builder/dockerfile.centos_core.build | 35 ---- builder/dockerfile.centos_core.rpm.build | 12 -- builder/dockerfile.centos_core.rpm.test | 64 ------- builder/scripts/common.sh | 5 +- builder/test-rpm-barebones | 4 +- centos/kasmvncserver.spec | 158 ------------------ 12 files changed, 13 insertions(+), 334 deletions(-) delete mode 100644 builder/dockerfile.centos_core.barebones.rpm.test delete mode 100644 builder/dockerfile.centos_core.build delete mode 100644 builder/dockerfile.centos_core.rpm.build delete mode 100644 builder/dockerfile.centos_core.rpm.test delete mode 100644 centos/kasmvncserver.spec diff --git a/BUILDING.txt b/BUILDING.txt index b0f3782..b792555 100644 --- a/BUILDING.txt +++ b/BUILDING.txt @@ -48,7 +48,7 @@ Build Requirements (Windows) You also need the Inno Setup Preprocessor, which is available in the Inno Setup QuickStart Pack. - Add the directory containing iscc.exe (for instance, + Add the directory containing iscc.exe (for instance, C:\Program Files\Inno Setup 5) to the system or user PATH environment variable prior to building KasmVNC. @@ -90,7 +90,7 @@ but the general outline is as follows. > cp -R {xorg_source}/* unix/xserver/ (NOTE: {xorg_source} is the directory containing the Xorg source for the machine on which you are building KasmVNC. The most recent versions of - Red Hat/CentOS/Fedora, for instance, provide an RPM called + Red Hat/Fedora, for instance, provide an RPM called "xorg-x11-server-source", which installs the Xorg source under /usr/share/xorg-x11-server-source.) @@ -113,8 +113,8 @@ but the general outline is as follows. --with-serverconfig-path=/usr/lib[64]/xorg \ --with-dri-driver-path=/usr/lib[64]/dri \ {additional configure options} - (NOTE: This is merely an example that works with Red Hat Enterprise/CentOS - 6 and recent Fedora releases. You should customize it for your particular + (NOTE: This is merely an example that works with Red Hat Enterprise + and recent Fedora releases. You should customize it for your particular system. In particular, it will be necessary to customize the font, XKB, and DRI directories.) @@ -187,7 +187,7 @@ Building TLS Support ====================================== TLS requires GnuTLS, which is supplied with most Linux distributions and -with MinGW for Windows and can be built from source on OS X and other +with MinGW for Windows and can be built from source on OS X and other Unix variants. However, GnuTLS versions > 2.12.x && < 3.3.x should be avoided because of potential incompatibilities during initial handshaking. @@ -314,7 +314,7 @@ X server source (for instance, --host=i686-pc-linux-gnu). Add -DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.5.sdk \ - -DCMAKE_OSX_DEPLOYMENT_TARGET=10.5 + -DCMAKE_OSX_DEPLOYMENT_TARGET=10.5 to the CMake command line. The OS X 10.5 SDK must be installed. @@ -406,7 +406,7 @@ Distribution-Specific Packaging =============================== -RPM Packages for RHEL / CentOS +RPM Packages for RHEL ------------------------------ The RPM spec files and patches used to create the nightly builds diff --git a/README.md b/README.md index 5efc230..ccc0f50 100644 --- a/README.md +++ b/README.md @@ -46,22 +46,6 @@ sudo dnf localinstall ./kasmvncserver_*.rpm sudo usermod -a -G kasmvnc-cert $USER ``` -### CentOS 7 - -```sh -# Please choose the package for your distro here (under Assets): -# https://github.com/kasmtech/KasmVNC/releases -wget - -# Ensure KasmVNC dependencies are available -sudo yum install epel-release - -sudo yum install ./kasmvncserver_*.rpm - -# Add your user to the kasmvnc-cert group -sudo usermod -a -G kasmvnc-cert $USER -``` - ## Getting Started The following examples provide basic usage of KasmVNC with the tools provided. For full documentation on all the utilities and the runtime environment, see our [KasmVNC Documentation](https://www.kasmweb.com/kasmvnc/docs/latest/index.html) @@ -250,7 +234,7 @@ command_line: - Keyboard input rate limit - Screen region selection - Deb packages for Debian, Ubuntu, and Kali Linux included in release. - - RPM packages for CentOS, Oracle, OpenSUSE, Fedora. RPM packages are currently not updatable and not released, though you can build and install them. See build documentation. + - RPM packages for Oracle, OpenSUSE, Fedora. RPM packages are currently not updatable and not released, though you can build and install them. See build documentation. - Web [API](https://github.com/kasmtech/KasmVNC/wiki/API) added for remotely controlling and getting information from KasmVNC - Multi-User support with permissions that can be changed via the API - Web UI uses a webpack for faster load times. diff --git a/builder/README.md b/builder/README.md index b5f5276..64b8513 100644 --- a/builder/README.md +++ b/builder/README.md @@ -20,14 +20,13 @@ builder/build-package ubuntu focal builder/build-package debian buster builder/build-package debian bullseye builder/build-package kali kali-rolling -builder/build-package centos core # CentOS 7 builder/build-package fedora thirtythree ``` # Build and test a package ``` builder/build-and-test-deb ubuntu focal -builder/build-and-test-rpm centos core +builder/build-and-test-rpm oracle 8 ``` Open browser and point to https://localhost:443/ or https://\:443/ diff --git a/builder/build.sh b/builder/build.sh index cb0541b..be9d899 100755 --- a/builder/build.sh +++ b/builder/build.sh @@ -9,13 +9,6 @@ detect_quilt() { fi } -ensure_crashpad_can_fetch_line_number_by_address() { - if [ ! -f /etc/centos-release ]; then - export LDFLAGS="$LDFLAGS -no-pie" - fi -} - - fail_on_gcc_12() { if [[ -n "$CC" && -n "$CXX" ]]; then return; @@ -89,11 +82,6 @@ autoreconf -i # The distro paths start after prefix and end with the font path, # everything after that is based on BUILDING.txt to remove unneeded # components. -ensure_crashpad_can_fetch_line_number_by_address -# Centos7 is too old for dri3 -if [ ! "${KASMVNC_BUILD_OS}" == "centos" ]; then - CONFIG_OPTIONS="--enable-dri3" -fi # remove gl check for opensuse if [ "${KASMVNC_BUILD_OS}" == "opensuse" ] || ([ "${KASMVNC_BUILD_OS}" == "oracle" ] && [ "${KASMVNC_BUILD_OS_CODENAME}" == 9 ]); then sed -i 's/LIBGL="gl >= 7.1.0"/LIBGL="gl >= 1.1"/g' configure diff --git a/builder/bump-package-version-rpm b/builder/bump-package-version-rpm index fe3fc4d..2ef427d 100755 --- a/builder/bump-package-version-rpm +++ b/builder/bump-package-version-rpm @@ -3,7 +3,7 @@ set -eo pipefail new_version="$1" -spec_dirs=(centos oracle opensuse fedora) +spec_dirs=(oracle opensuse fedora) spec_files() { for d in "${spec_dirs[@]}"; do diff --git a/builder/dockerfile.centos_core.barebones.rpm.test b/builder/dockerfile.centos_core.barebones.rpm.test deleted file mode 100644 index 84dcd08..0000000 --- a/builder/dockerfile.centos_core.barebones.rpm.test +++ /dev/null @@ -1,20 +0,0 @@ -FROM centos:centos7 - -ENV STARTUPDIR=/dockerstartup - -RUN yum install -y xterm -RUN yum install -y vim less -RUN yum install -y redhat-lsb-core -RUN yum install -y epel-release - -ARG KASMVNC_PACKAGE_DIR -COPY $KASMVNC_PACKAGE_DIR/*.rpm /tmp/ -RUN yum localinstall -y /tmp/*.rpm - -RUN mkdir -p $STARTUPDIR -COPY startup/vnc_startup_barebones.sh $STARTUPDIR - -RUN useradd -m foo -USER foo:kasmvnc-cert - -ENTRYPOINT "/$STARTUPDIR/vnc_startup_barebones.sh" diff --git a/builder/dockerfile.centos_core.build b/builder/dockerfile.centos_core.build deleted file mode 100644 index cb6d4fa..0000000 --- a/builder/dockerfile.centos_core.build +++ /dev/null @@ -1,35 +0,0 @@ -FROM centos:centos7 - -ENV KASMVNC_BUILD_OS centos -ENV KASMVNC_BUILD_OS_CODENAME core - -RUN yum install -y ca-certificates -RUN yum install -y build-dep xorg-server libxfont-dev sudo -RUN yum install -y gcc cmake git libgnutls28-dev vim wget tightvncserver -RUN yum install -y libpng-dev libtiff-dev libgif-dev libavcodec-dev openssl-devel -RUN yum install -y make -RUN yum group install -y "Development Tools" -RUN yum install -y xorg-x11-server-devel zlib-devel -RUN yum install -y libxkbfile-devel libXfont2-devel xorg-x11-font-utils \ - xorg-x11-xtrans-devel xorg-x11-xkb-utils-devel libXrandr-devel pam-devel \ - gnutls-devel libX11-devel libXtst-devel libXcursor-devel -RUN yum install -y mesa-dri-drivers -RUN yum install -y ca-certificates - -# Additions for webp -RUN cd /tmp && wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.0.2.tar.gz -RUN cd /tmp && tar -xzf /tmp/libwebp-* -RUN cd /tmp/libwebp-1.0.2 && \ - ./configure --enable-static --disable-shared && \ - make && make install - -ENV SCRIPTS_DIR=/tmp/scripts -COPY builder/scripts $SCRIPTS_DIR -RUN $SCRIPTS_DIR/build-libjpeg-turbo - -RUN useradd -m docker && echo "docker:docker" | chpasswd - -COPY --chown=docker:docker . /src/ - -USER docker -ENTRYPOINT ["/src/builder/build.sh"] diff --git a/builder/dockerfile.centos_core.rpm.build b/builder/dockerfile.centos_core.rpm.build deleted file mode 100644 index 7a4e208..0000000 --- a/builder/dockerfile.centos_core.rpm.build +++ /dev/null @@ -1,12 +0,0 @@ -FROM centos:centos7 - -RUN yum install -y rpm* gpg* rng-tools rpmlint -RUN yum install -y tree vim less -RUN yum install -y redhat-lsb-core - -COPY centos/*.spec /tmp -RUN yum-builddep -y /tmp/*.spec - -RUN useradd -m docker && echo "docker:docker" | chpasswd - -USER docker diff --git a/builder/dockerfile.centos_core.rpm.test b/builder/dockerfile.centos_core.rpm.test deleted file mode 100644 index 4ae4377..0000000 --- a/builder/dockerfile.centos_core.rpm.test +++ /dev/null @@ -1,64 +0,0 @@ -FROM centos:centos7 - -ENV DISPLAY=:1 \ - VNC_PORT=8443 \ - VNC_RESOLUTION=1280x720 \ - MAX_FRAME_RATE=24 \ - VNCOPTIONS="-PreferBandwidth -DynamicQualityMin=4 -DynamicQualityMax=7" \ - HOME=/home/user \ - TERM=xterm \ - STARTUPDIR=/dockerstartup \ - INST_SCRIPTS=/dockerstartup/install \ - KASM_RX_HOME=/dockerstartup/kasmrx \ - DEBIAN_FRONTEND=noninteractive \ - VNC_COL_DEPTH=24 \ - VNC_RESOLUTION=1280x1024 \ - VNC_PW=vncpassword \ - VNC_USER=user \ - VNC_VIEW_ONLY_PW=vncviewonlypassword \ - LD_LIBRARY_PATH=/usr/local/lib/ \ - OMP_WAIT_POLICY=PASSIVE \ - SHELL=/bin/bash \ - SINGLE_APPLICATION=0 \ - KASMVNC_BUILD_OS=centos \ - KASMVNC_BUILD_OS_CODENAME=core - -EXPOSE $VNC_PORT - -WORKDIR $HOME - -### REQUIRED STUFF ### - -RUN yum install -y openssl xterm gettext wget -RUN yum install -y centos-release-scl-rh && yum install -y nss_wrapper -RUN yum install -y xorg-x11-server xorg-x11-xauth xorg-x11-xkb-utils \ - xkeyboard-config xorg-x11-server-utils -RUN yum install -y epel-release && yum groupinstall xfce -y -RUN yum erase -y pm-utils xscreensaver* -RUN yum install -y redhat-lsb-core -RUN yum install -y vim less - -RUN echo 'source $STARTUPDIR/generate_container_user' >> $HOME/.bashrc - -RUN mkdir -p $STARTUPDIR -COPY builder/startup/ $STARTUPDIR - -### START CUSTOM STUFF #### - -COPY ./builder/scripts/ /tmp/scripts/ -COPY ./centos/kasmvncserver.spec /tmp - -ARG KASMVNC_PACKAGE_DIR -COPY $KASMVNC_PACKAGE_DIR/*.rpm /tmp/ -RUN /tmp/scripts/install_kasmvncserver_package - -### END CUSTOM STUFF ### - -RUN chown -R 1000:0 $HOME -USER 1000:kasmvnc-cert -WORKDIR $HOME - -RUN mkdir ~/.vnc && echo '/usr/bin/xfce4-session &' >> ~/.vnc/xstartup && \ - chmod +x ~/.vnc/xstartup - -ENTRYPOINT [ "/dockerstartup/vnc_startup.sh" ] diff --git a/builder/scripts/common.sh b/builder/scripts/common.sh index 4440b66..e22deef 100644 --- a/builder/scripts/common.sh +++ b/builder/scripts/common.sh @@ -1,9 +1,7 @@ #!/bin/bash detect_distro() { - if [ -f /etc/centos-release ]; then - DISTRO=centos - elif [ -f /etc/oracle-release ]; then + if [ -f /etc/oracle-release ]; then DISTRO=oracle elif [ -f /etc/fedora-release ]; then DISTRO=fedora @@ -20,7 +18,6 @@ install_packages() { local install_cmd=no-command-defined case "$DISTRO" in - centos) install_cmd="yum install -y" ;; oracle) install_cmd="dnf install -y" ;; fedora) install_cmd="dnf install -y" ;; opensuse) install_cmd="zypper install -y" ;; diff --git a/builder/test-rpm-barebones b/builder/test-rpm-barebones index 6318bda..ea4cae6 100755 --- a/builder/test-rpm-barebones +++ b/builder/test-rpm-barebones @@ -5,8 +5,8 @@ set -e cd "$(dirname "$0")" . ./process_test_options.sh . ./common.sh -os="${1:-centos}" -os_codename="${2:-core}" +os="${1:-oracle}" +os_codename="${2:-8}" docker build --build-arg KASMVNC_PACKAGE_DIR="build/${os}_${os_codename}" \ -t kasmvnctester_barebones_${os}:$os_codename \ diff --git a/centos/kasmvncserver.spec b/centos/kasmvncserver.spec deleted file mode 100644 index b860978..0000000 --- a/centos/kasmvncserver.spec +++ /dev/null @@ -1,158 +0,0 @@ -Name: kasmvncserver -Version: 1.3.3 -Release: 1%{?dist} -Summary: VNC server accessible from a web browser - -License: GPLv2+ -URL: https://github.com/kasmtech/KasmVNC - -BuildRequires: rsync -Requires: xorg-x11-xauth, xorg-x11-xkb-utils, xkeyboard-config, xorg-x11-server-utils, openssl, perl, perl-Switch, perl-YAML-Tiny, perl-Hash-Merge-Simple, perl-Scalar-List-Utils, perl-List-MoreUtils, perl-Try-Tiny, perl-DateTime-TimeZone -Conflicts: tigervnc-server, tigervnc-server-minimal - -%description -KasmVNC provides remote web-based access to a Desktop or application. -While VNC is in the name, KasmVNC differs from other VNC variants such -as TigerVNC, RealVNC, and TurboVNC. KasmVNC has broken from the RFB -specification which defines VNC, in order to support modern technologies -and increase security. KasmVNC is accessed by users from any modern -browser and does not support legacy VNC viewer applications. KasmVNC -uses a modern YAML based configuration at the server and user level, -allowing for ease of management. KasmVNC is maintained by Kasm -Technologies Corp, www.kasmweb.com. - -WARNING: this package requires EPEL. - -%prep - -%install -rm -rf $RPM_BUILD_ROOT - -TARGET_OS=$(lsb_release -is | tr '[:upper:]' '[:lower:]') -TARGET_OS_CODENAME=$(lsb_release -cs | tr '[:upper:]' '[:lower:]') -TARBALL=$RPM_SOURCE_DIR/kasmvnc.${TARGET_OS}_${TARGET_OS_CODENAME}.tar.gz -TAR_DATA=$(mktemp -d) -tar -xzf "$TARBALL" -C "$TAR_DATA" - -SRC=$TAR_DATA/usr/local -SRC_BIN=$SRC/bin -DESTDIR=$RPM_BUILD_ROOT -DST_MAN=$DESTDIR/usr/share/man/man1 - -mkdir -p $DESTDIR/usr/bin $DESTDIR/usr/share/man/man1 \ - $DESTDIR/usr/share/doc/kasmvncserver $DESTDIR/usr/lib \ - $DESTDIR/usr/share/perl5 $DESTDIR/etc/kasmvnc - -cp $SRC_BIN/Xvnc $DESTDIR/usr/bin; -cp $SRC_BIN/vncserver $DESTDIR/usr/bin; -cp -a $SRC_BIN/KasmVNC $DESTDIR/usr/share/perl5/ -cp $SRC_BIN/vncconfig $DESTDIR/usr/bin; -cp $SRC_BIN/kasmvncpasswd $DESTDIR/usr/bin; -cp $SRC_BIN/kasmxproxy $DESTDIR/usr/bin; -cp -r $SRC/lib/kasmvnc/ $DESTDIR/usr/lib/kasmvncserver -cd $DESTDIR/usr/bin && ln -s kasmvncpasswd vncpasswd; -cp -r $SRC/share/doc/kasmvnc*/* $DESTDIR/usr/share/doc/kasmvncserver/ -rsync -r --links --safe-links --exclude '.git*' --exclude po2js --exclude xgettext-html \ - --exclude www/utils/ --exclude .eslintrc --exclude configure \ - $SRC/share/kasmvnc $DESTDIR/usr/share - -sed -i -e 's!pem_certificate: .\+$!pem_certificate: /etc/pki/tls/private/kasmvnc.pem!' \ - $DESTDIR/usr/share/kasmvnc/kasmvnc_defaults.yaml -sed -i -e 's!pem_key: .\+$!pem_key: /etc/pki/tls/private/kasmvnc.pem!' \ - $DESTDIR/usr/share/kasmvnc/kasmvnc_defaults.yaml -sed -e 's/^\([^#]\)/# \1/' $DESTDIR/usr/share/kasmvnc/kasmvnc_defaults.yaml > \ - $DESTDIR/etc/kasmvnc/kasmvnc.yaml -cp $SRC/man/man1/Xvnc.1 $DESTDIR/usr/share/man/man1/; -cp $SRC/share/man/man1/vncserver.1 $DST_MAN; -cp $SRC/share/man/man1/vncconfig.1 $DST_MAN; -cp $SRC/share/man/man1/vncpasswd.1 $DST_MAN; -cp $SRC/share/man/man1/kasmxproxy.1 $DST_MAN; -cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1; - - -%files -%config(noreplace) /etc/kasmvnc - -/usr/bin/* -/usr/lib/kasmvncserver -/usr/share/man/man1/* -/usr/share/perl5/KasmVNC -/usr/share/kasmvnc - -%license /usr/share/doc/kasmvncserver/LICENSE.TXT -%doc /usr/share/doc/kasmvncserver/README.md - -%changelog -* Fri Oct 25 2024 KasmTech - 1.3.3-1 -- Allow disabling IP blacklist -- Downloads API for detailed file downloads information -* Tue Sep 24 2024 KasmTech - 1.3.2-1 -- Disable seamless clipboard on Firefox by default, due to the Firefox overlaying a Paste menu over the canvas. -- Fixed CVE-2024-38449, directory traversal bug in built-in web server. -- Allow for larger header sizes, up to 16k. Provide better logging and handling for requests that contain HTTP headers that are larger than the 16k limit. -- Fixed memory leak in kasmproxy. -- Fixed mime types of downloads to ensure the browser interprets them as downloads. -* Tue Mar 12 2024 KasmTech - 1.3.1-1 -- Fix exception thrown on Firefox 124 and higher -- Fix artifacts on high resolution secondary screens -- Fixes for touch support on primary and secondary screens -- Fix for Oculus keyboard input -* Mon Feb 05 2024 KasmTech - 1.3.0-1 -- Multi-monitor support. -- Increased performance with watermark enabled. -- Added support for Fedora 39 and Alpine 319. -- Allow special characters in usernames. -- Better logging of client settings when client connects or changes settings. -- Add support for rotation of text-based watermark. -* Fri Aug 25 2023 KasmTech - 1.2.0-1 -- Add support for Unix relays for bidirectional communication between noVNC - and containerized applications. -- Text based watermark overlays with date and time support. -- New builds for Bookworm, Alpine 3.18, and Fedora 38. -- Multi-language support. -- Add support for rendering pixmaps via DRI3 GPU acceleration allowing - compositing and other 3d accelerated workloads in a KasmVNC session. -- Fix crash that can occur. -- Fixed tearing when compositing is enabled with DRI3 hardware acceleration. -- Fix stuck command key on MacOS clients. -* Wed Apr 05 2023 KasmTech - 1.1.0-1 -- Upstream release -* Tue Nov 29 2022 KasmTech - 1.0.0-1 -- WebRTC UDP transit support with support of STUN servers -- Lossless compression using multi-threaded WASM QOI decoder client side -- New yaml based configuration -- Significantly improved FPS through both client-side and server-side improvements. -- Support for the admin to define arbitrary http response headers for the built in web server -- Support for additional mouse buttons -- Refinement of vncserver checks and user prompts -- Added send_full_frame to developer API, forces full frame to be sent to all connected users that have at least read permission. -* Tue Mar 22 2022 KasmTech - 0.9.3~beta-1 -* Fri Feb 12 2021 KasmTech - 0.9.1~beta-1 -- Initial release of the rpm package. - -%post - kasmvnc_group="kasmvnc-cert" - - create_kasmvnc_group() { - if ! getent group "$kasmvnc_group" >/dev/null; then - groupadd --system "$kasmvnc_group" - fi - } - - make_self_signed_certificate() { - local cert_file=/etc/pki/tls/private/kasmvnc.pem - [ -f "$cert_file" ] && return 0 - - openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \ - -keyout "$cert_file" \ - -out "$cert_file" -subj \ - "/C=US/ST=VA/L=None/O=None/OU=DoFu/CN=kasm/emailAddress=none@none.none" - chgrp "$kasmvnc_group" "$cert_file" - chmod 640 "$cert_file" - } - - create_kasmvnc_group - make_self_signed_certificate - -%postun - rm -f /etc/pki/tls/private/kasmvnc.pem From b69b660d738b1550ec52ce6d91a1deb0b6c1c3e2 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 31 Jan 2025 18:25:24 +1300 Subject: [PATCH 006/167] KASM-6518 Remove support for Fedora 37, 38 --- .gitlab-ci.yml | 76 ---------------- ...file.fedora_thirtyeight.barebones.rpm.test | 19 ---- builder/dockerfile.fedora_thirtyeight.build | 86 ------------------- .../dockerfile.fedora_thirtyeight.rpm.build | 13 --- .../dockerfile.fedora_thirtyeight.rpm.test | 62 ------------- ...file.fedora_thirtyseven.barebones.rpm.test | 19 ---- builder/dockerfile.fedora_thirtyseven.build | 86 ------------------- .../dockerfile.fedora_thirtyseven.rpm.build | 13 --- .../dockerfile.fedora_thirtyseven.rpm.test | 62 ------------- 9 files changed, 436 deletions(-) delete mode 100644 builder/dockerfile.fedora_thirtyeight.barebones.rpm.test delete mode 100644 builder/dockerfile.fedora_thirtyeight.build delete mode 100644 builder/dockerfile.fedora_thirtyeight.rpm.build delete mode 100644 builder/dockerfile.fedora_thirtyeight.rpm.test delete mode 100644 builder/dockerfile.fedora_thirtyseven.barebones.rpm.test delete mode 100644 builder/dockerfile.fedora_thirtyseven.build delete mode 100644 builder/dockerfile.fedora_thirtyseven.rpm.build delete mode 100644 builder/dockerfile.fedora_thirtyseven.rpm.test diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 295c93b..f3f8a26 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -447,82 +447,6 @@ build_opensuse_15_arm: paths: - output/ -build_fedora_thirtyseven: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora thirtyseven; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_thirtyseven_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora thirtyseven; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_thirtyeight: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora thirtyeight; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_thirtyeight_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora thirtyeight; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - build_fedora_thirtynine: stage: build allow_failure: true diff --git a/builder/dockerfile.fedora_thirtyeight.barebones.rpm.test b/builder/dockerfile.fedora_thirtyeight.barebones.rpm.test deleted file mode 100644 index 4252609..0000000 --- a/builder/dockerfile.fedora_thirtyeight.barebones.rpm.test +++ /dev/null @@ -1,19 +0,0 @@ -FROM fedora:38 - -ENV STARTUPDIR=/dockerstartup - -RUN dnf install -y xterm -RUN dnf install -y vim less -RUN yum install -y redhat-lsb-core - -ARG KASMVNC_PACKAGE_DIR -COPY $KASMVNC_PACKAGE_DIR/*.rpm /tmp/ -RUN dnf localinstall -y /tmp/*.rpm - -RUN mkdir -p $STARTUPDIR -COPY startup/vnc_startup_barebones.sh $STARTUPDIR - -RUN useradd -m foo -USER foo:kasmvnc-cert - -ENTRYPOINT "/$STARTUPDIR/vnc_startup_barebones.sh" diff --git a/builder/dockerfile.fedora_thirtyeight.build b/builder/dockerfile.fedora_thirtyeight.build deleted file mode 100644 index dbfae34..0000000 --- a/builder/dockerfile.fedora_thirtyeight.build +++ /dev/null @@ -1,86 +0,0 @@ -FROM fedora:38 - -ENV KASMVNC_BUILD_OS fedora -ENV KASMVNC_BUILD_OS_CODENAME thirtyeight -ENV XORG_VER 1.20.14 - -RUN \ - echo "**** install build deps ****" && \ - dnf group install -y \ - "C Development Tools and Libraries" \ - "Development Tools" && \ - dnf install -y \ - autoconf \ - automake \ - bison \ - byacc \ - bzip2 \ - cmake \ - diffutils \ - doxygen \ - file \ - flex \ - fop \ - gcc \ - gcc-c++ \ - git \ - glibc-devel \ - libdrm-devel \ - libepoxy-devel \ - libmd-devel \ - libpciaccess-devel \ - libtool \ - libwebp-devel \ - libX11-devel \ - libXau-devel \ - libxcb-devel \ - libXcursor-devel \ - libxcvt-devel \ - libXdmcp-devel \ - libXext-devel \ - libXfont2-devel \ - libxkbfile-devel \ - libXrandr-devel \ - libxshmfence-devel \ - libXtst-devel \ - mesa-libEGL-devel \ - mesa-libgbm-devel \ - mesa-libGL-devel \ - meson \ - mingw64-binutils \ - mt-st \ - nettle-devel \ - openssl-devel \ - patch \ - pixman-devel \ - wayland-devel \ - wget \ - which \ - xcb-util-devel \ - xcb-util-image-devel \ - xcb-util-keysyms-devel \ - xcb-util-renderutil-devel \ - xcb-util-wm-devel \ - xinit \ - xkbcomp \ - xkbcomp-devel \ - xkeyboard-config \ - xmlto \ - xorg-x11-font-utils \ - xorg-x11-proto-devel \ - xorg-x11-server-common \ - xorg-x11-server-devel \ - xorg-x11-xtrans-devel \ - xsltproc - -ENV SCRIPTS_DIR=/tmp/scripts -COPY builder/scripts $SCRIPTS_DIR -RUN $SCRIPTS_DIR/build-webp -RUN $SCRIPTS_DIR/build-libjpeg-turbo - -RUN useradd -m docker && echo "docker:docker" | chpasswd - -COPY --chown=docker:docker . /src/ - -USER docker -ENTRYPOINT ["/src/builder/build.sh"] diff --git a/builder/dockerfile.fedora_thirtyeight.rpm.build b/builder/dockerfile.fedora_thirtyeight.rpm.build deleted file mode 100644 index 8fc556f..0000000 --- a/builder/dockerfile.fedora_thirtyeight.rpm.build +++ /dev/null @@ -1,13 +0,0 @@ -FROM fedora:38 - -RUN dnf install -y fedora-packager fedora-review -RUN dnf install -y tree vim less -RUN dnf install -y redhat-lsb-core -RUN dnf install -y dnf-plugins-core - -COPY fedora/*.spec /tmp -RUN dnf builddep -y /tmp/*.spec - -RUN useradd -m docker && echo "docker:docker" | chpasswd - -USER docker diff --git a/builder/dockerfile.fedora_thirtyeight.rpm.test b/builder/dockerfile.fedora_thirtyeight.rpm.test deleted file mode 100644 index 16975a0..0000000 --- a/builder/dockerfile.fedora_thirtyeight.rpm.test +++ /dev/null @@ -1,62 +0,0 @@ -FROM fedora:38 - -ENV DISPLAY=:1 \ - VNC_PORT=8443 \ - VNC_RESOLUTION=1280x720 \ - MAX_FRAME_RATE=24 \ - VNCOPTIONS="-PreferBandwidth -DynamicQualityMin=4 -DynamicQualityMax=7" \ - HOME=/home/user \ - TERM=xterm \ - STARTUPDIR=/dockerstartup \ - INST_SCRIPTS=/dockerstartup/install \ - KASM_RX_HOME=/dockerstartup/kasmrx \ - DEBIAN_FRONTEND=noninteractive \ - VNC_COL_DEPTH=24 \ - VNC_RESOLUTION=1280x1024 \ - VNC_PW=vncpassword \ - VNC_USER=user \ - VNC_VIEW_ONLY_PW=vncviewonlypassword \ - LD_LIBRARY_PATH=/usr/local/lib/ \ - OMP_WAIT_POLICY=PASSIVE \ - SHELL=/bin/bash \ - SINGLE_APPLICATION=0 \ - KASMVNC_BUILD_OS=fedora \ - KASMVNC_BUILD_OS_CODENAME=thirtythree - -EXPOSE $VNC_PORT - -WORKDIR $HOME - -### REQUIRED STUFF ### - -RUN dnf install -y openssl xterm gettext wget -RUN dnf install -y nss_wrapper -RUN dnf install -y xorg-x11-xauth xkeyboard-config -# xorg-x11-server-Xorg -# RUN dnf install -y @xfce-desktop-environment -RUN dnf erase -y pm-utils xscreensaver* -RUN dnf install -y redhat-lsb-core -RUN dnf install -y vim less -RUN dnf install -y @xfce-desktop-environment - -RUN echo 'source $STARTUPDIR/generate_container_user' >> $HOME/.bashrc - -RUN mkdir -p $STARTUPDIR -COPY builder/startup/ $STARTUPDIR - -### START CUSTOM STUFF #### -COPY ./builder/scripts/ /tmp/scripts/ -COPY ./fedora/kasmvncserver.spec /tmp - -ARG KASMVNC_PACKAGE_DIR -COPY $KASMVNC_PACKAGE_DIR/*.rpm /tmp/ -# RUN dnf remove -y tigervnc-server-minimal -RUN /tmp/scripts/install_kasmvncserver_package - -### END CUSTOM STUFF ### - -RUN chown -R 1000:0 $HOME -USER 1000:kasmvnc-cert -WORKDIR $HOME - -ENTRYPOINT [ "/dockerstartup/vnc_startup.sh" ] diff --git a/builder/dockerfile.fedora_thirtyseven.barebones.rpm.test b/builder/dockerfile.fedora_thirtyseven.barebones.rpm.test deleted file mode 100644 index ba97bf8..0000000 --- a/builder/dockerfile.fedora_thirtyseven.barebones.rpm.test +++ /dev/null @@ -1,19 +0,0 @@ -FROM fedora:37 - -ENV STARTUPDIR=/dockerstartup - -RUN dnf install -y xterm -RUN dnf install -y vim less -RUN yum install -y redhat-lsb-core - -ARG KASMVNC_PACKAGE_DIR -COPY $KASMVNC_PACKAGE_DIR/*.rpm /tmp/ -RUN dnf localinstall -y /tmp/*.rpm - -RUN mkdir -p $STARTUPDIR -COPY startup/vnc_startup_barebones.sh $STARTUPDIR - -RUN useradd -m foo -USER foo:kasmvnc-cert - -ENTRYPOINT "/$STARTUPDIR/vnc_startup_barebones.sh" diff --git a/builder/dockerfile.fedora_thirtyseven.build b/builder/dockerfile.fedora_thirtyseven.build deleted file mode 100644 index 4557431..0000000 --- a/builder/dockerfile.fedora_thirtyseven.build +++ /dev/null @@ -1,86 +0,0 @@ -FROM fedora:37 - -ENV KASMVNC_BUILD_OS fedora -ENV KASMVNC_BUILD_OS_CODENAME thirtyseven -ENV XORG_VER 1.20.14 - -RUN \ - echo "**** install build deps ****" && \ - dnf group install -y \ - "C Development Tools and Libraries" \ - "Development Tools" && \ - dnf install -y \ - autoconf \ - automake \ - bison \ - byacc \ - bzip2 \ - cmake \ - diffutils \ - doxygen \ - file \ - flex \ - fop \ - gcc \ - gcc-c++ \ - git \ - glibc-devel \ - libdrm-devel \ - libepoxy-devel \ - libmd-devel \ - libpciaccess-devel \ - libtool \ - libwebp-devel \ - libX11-devel \ - libXau-devel \ - libxcb-devel \ - libXcursor-devel \ - libxcvt-devel \ - libXdmcp-devel \ - libXext-devel \ - libXfont2-devel \ - libxkbfile-devel \ - libXrandr-devel \ - libxshmfence-devel \ - libXtst-devel \ - mesa-libEGL-devel \ - mesa-libgbm-devel \ - mesa-libGL-devel \ - meson \ - mingw64-binutils \ - mt-st \ - nettle-devel \ - openssl-devel \ - patch \ - pixman-devel \ - wayland-devel \ - wget \ - which \ - xcb-util-devel \ - xcb-util-image-devel \ - xcb-util-keysyms-devel \ - xcb-util-renderutil-devel \ - xcb-util-wm-devel \ - xinit \ - xkbcomp \ - xkbcomp-devel \ - xkeyboard-config \ - xmlto \ - xorg-x11-font-utils \ - xorg-x11-proto-devel \ - xorg-x11-server-common \ - xorg-x11-server-devel \ - xorg-x11-xtrans-devel \ - xsltproc - -ENV SCRIPTS_DIR=/tmp/scripts -COPY builder/scripts $SCRIPTS_DIR -RUN $SCRIPTS_DIR/build-webp -RUN $SCRIPTS_DIR/build-libjpeg-turbo - -RUN useradd -m docker && echo "docker:docker" | chpasswd - -COPY --chown=docker:docker . /src/ - -USER docker -ENTRYPOINT ["/src/builder/build.sh"] diff --git a/builder/dockerfile.fedora_thirtyseven.rpm.build b/builder/dockerfile.fedora_thirtyseven.rpm.build deleted file mode 100644 index 8384b10..0000000 --- a/builder/dockerfile.fedora_thirtyseven.rpm.build +++ /dev/null @@ -1,13 +0,0 @@ -FROM fedora:37 - -RUN dnf install -y fedora-packager fedora-review -RUN dnf install -y tree vim less -RUN dnf install -y redhat-lsb-core -RUN dnf install -y dnf-plugins-core - -COPY fedora/*.spec /tmp -RUN dnf builddep -y /tmp/*.spec - -RUN useradd -m docker && echo "docker:docker" | chpasswd - -USER docker diff --git a/builder/dockerfile.fedora_thirtyseven.rpm.test b/builder/dockerfile.fedora_thirtyseven.rpm.test deleted file mode 100644 index 5c7dea3..0000000 --- a/builder/dockerfile.fedora_thirtyseven.rpm.test +++ /dev/null @@ -1,62 +0,0 @@ -FROM fedora:37 - -ENV DISPLAY=:1 \ - VNC_PORT=8443 \ - VNC_RESOLUTION=1280x720 \ - MAX_FRAME_RATE=24 \ - VNCOPTIONS="-PreferBandwidth -DynamicQualityMin=4 -DynamicQualityMax=7" \ - HOME=/home/user \ - TERM=xterm \ - STARTUPDIR=/dockerstartup \ - INST_SCRIPTS=/dockerstartup/install \ - KASM_RX_HOME=/dockerstartup/kasmrx \ - DEBIAN_FRONTEND=noninteractive \ - VNC_COL_DEPTH=24 \ - VNC_RESOLUTION=1280x1024 \ - VNC_PW=vncpassword \ - VNC_USER=user \ - VNC_VIEW_ONLY_PW=vncviewonlypassword \ - LD_LIBRARY_PATH=/usr/local/lib/ \ - OMP_WAIT_POLICY=PASSIVE \ - SHELL=/bin/bash \ - SINGLE_APPLICATION=0 \ - KASMVNC_BUILD_OS=fedora \ - KASMVNC_BUILD_OS_CODENAME=thirtythree - -EXPOSE $VNC_PORT - -WORKDIR $HOME - -### REQUIRED STUFF ### - -RUN dnf install -y openssl xterm gettext wget -RUN dnf install -y nss_wrapper -RUN dnf install -y xorg-x11-xauth xkeyboard-config -# xorg-x11-server-Xorg -# RUN dnf install -y @xfce-desktop-environment -RUN dnf erase -y pm-utils xscreensaver* -RUN dnf install -y redhat-lsb-core -RUN dnf install -y vim less -RUN dnf install -y @xfce-desktop-environment - -RUN echo 'source $STARTUPDIR/generate_container_user' >> $HOME/.bashrc - -RUN mkdir -p $STARTUPDIR -COPY builder/startup/ $STARTUPDIR - -### START CUSTOM STUFF #### -COPY ./builder/scripts/ /tmp/scripts/ -COPY ./fedora/kasmvncserver.spec /tmp - -ARG KASMVNC_PACKAGE_DIR -COPY $KASMVNC_PACKAGE_DIR/*.rpm /tmp/ -# RUN dnf remove -y tigervnc-server-minimal -RUN /tmp/scripts/install_kasmvncserver_package - -### END CUSTOM STUFF ### - -RUN chown -R 1000:0 $HOME -USER 1000:kasmvnc-cert -WORKDIR $HOME - -ENTRYPOINT [ "/dockerstartup/vnc_startup.sh" ] From 8f410e1887485c80ce22f0817111bc025aac132e Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Thu, 6 Feb 2025 18:37:54 +1300 Subject: [PATCH 007/167] KASM-6518 Remove Debian Buster support --- .gitlab-ci.yml | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f3f8a26..93d2610 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -180,44 +180,6 @@ build_ubuntu_noble_arm: paths: - output/ -build_debian_buster: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package debian buster; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_debian_buster_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package debian buster; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - build_debian_bullseye: stage: build allow_failure: true From 03d99c1456f2c704ea321fd3b83cd576f3df1243 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Tue, 11 Feb 2025 15:51:50 +1300 Subject: [PATCH 008/167] KASM-6670 Fedora: add missing dependency on hostname --- fedora/kasmvncserver.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fedora/kasmvncserver.spec b/fedora/kasmvncserver.spec index 260d5ce..739530c 100644 --- a/fedora/kasmvncserver.spec +++ b/fedora/kasmvncserver.spec @@ -7,7 +7,7 @@ License: GPLv2+ URL: https://github.com/kasmtech/KasmVNC BuildRequires: rsync -Requires: xorg-x11-xauth, xkeyboard-config, xkbcomp, openssl, perl, perl-Switch, perl-YAML-Tiny, perl-Hash-Merge-Simple, perl-Scalar-List-Utils, perl-List-MoreUtils, perl-Try-Tiny, perl-DateTime-TimeZone, mesa-libgbm, libxshmfence +Requires: xorg-x11-xauth, xkeyboard-config, xkbcomp, openssl, perl, perl-Switch, perl-YAML-Tiny, perl-Hash-Merge-Simple, perl-Scalar-List-Utils, perl-List-MoreUtils, perl-Try-Tiny, perl-DateTime-TimeZone, mesa-libgbm, libxshmfence, hostname Conflicts: tigervnc-server, tigervnc-server-minimal %description From d933dc99abddeee71f0a6baca3cf072467283a7f Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Tue, 11 Feb 2025 20:10:22 +1300 Subject: [PATCH 009/167] KASM-5204 Add config key network.udp.payload_size --- unix/kasmvnc_defaults.yaml | 1 + unix/vncserver | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/unix/kasmvnc_defaults.yaml b/unix/kasmvnc_defaults.yaml index 292e93d..3d0551c 100644 --- a/unix/kasmvnc_defaults.yaml +++ b/unix/kasmvnc_defaults.yaml @@ -18,6 +18,7 @@ network: udp: public_ip: auto port: auto + payload_size: auto stun_server: auto ssl: pem_certificate: /etc/ssl/certs/ssl-cert-snakeoil.pem diff --git a/unix/vncserver b/unix/vncserver index ecdec9e..41fc1be 100755 --- a/unix/vncserver +++ b/unix/vncserver @@ -2366,6 +2366,24 @@ sub DefineConfigToCLIConversion { $value; } }), + KasmVNC::CliOption->new({ + name => 'udpSize', + configKeys => [ + KasmVNC::ConfigKey->new({ + name => "network.udp.payload_size", + validator => KasmVNC::PatternValidator->new({ + pattern => qr/^(auto|\d+)$/, + errorMessage => "must be 'auto' or an integer" + }), + }) + ], + isActiveSub => sub { + $self = shift; + + my $value = $self->configValue(); + isPresent($value) && $value ne 'auto'; + } + }), KasmVNC::CliOption->new({ name => 'udpPort', configKeys => [ From fc7e77499a4cf8113e005218b17a8b5ae572d058 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 23 Feb 2025 00:48:51 +0000 Subject: [PATCH 010/167] Resolve KASM-6894 "Feature/ remove webpack to reduce vulnerabilities" --- .gitmodules | 2 +- builder/build_www.sh | 14 +++----------- builder/dockerfile.www.build | 6 ++++-- kasmweb | 2 +- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/.gitmodules b/.gitmodules index 95fb845..e43a13a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "kasmweb"] path = kasmweb url = https://github.com/kasmtech/noVNC.git - branch = release/1.2.2 + branch = master diff --git a/builder/build_www.sh b/builder/build_www.sh index ec54f6c..b084dcf 100755 --- a/builder/build_www.sh +++ b/builder/build_www.sh @@ -1,18 +1,10 @@ -#!/bin/bash +#!/bin/sh # clear previous build rm -rf /build/* # build webpack npm run build -# remove node stuff from directory -rm -rf node_modules/ -# copy all to build dir -cp -R ./* /build/ -# remove unneccesary files -cd /build -rm *.md -rm AUTHORS -rm vnc.html -ln -s index.html vnc.html +# copy all to build dir +cp -R ./dist/* /build/ diff --git a/builder/dockerfile.www.build b/builder/dockerfile.www.build index be30b4b..e5a1845 100644 --- a/builder/dockerfile.www.build +++ b/builder/dockerfile.www.build @@ -1,6 +1,8 @@ -FROM node:12-buster +FROM alpine -COPY kasmweb/ /src/www/ +RUN apk add npm nodejs + +COPY kasmweb/ /src/www COPY builder/build_www.sh /src/ WORKDIR /src/www diff --git a/kasmweb b/kasmweb index bce2d6a..5c46b2e 160000 --- a/kasmweb +++ b/kasmweb @@ -1 +1 @@ -Subproject commit bce2d6a7048025c6e6c05df9d98b206c23f6dbab +Subproject commit 5c46b2e13ab1dd7232b28f017fd7e49ca740f5a4 From a3fd98e73163e16a824c8c53c5bf73c3b5135360 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Mon, 24 Feb 2025 19:31:10 +1300 Subject: [PATCH 011/167] KASM-6904 WIP --- alpine/alpine-devenv.dockerfile | 13 ++++ alpine/build | 1 + alpine/kasmvncserver/APKBUILD | 101 ++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 alpine/alpine-devenv.dockerfile create mode 100755 alpine/build create mode 100644 alpine/kasmvncserver/APKBUILD diff --git a/alpine/alpine-devenv.dockerfile b/alpine/alpine-devenv.dockerfile new file mode 100644 index 0000000..89d42f8 --- /dev/null +++ b/alpine/alpine-devenv.dockerfile @@ -0,0 +1,13 @@ +FROM alpine:3.21 + +RUN apk add abuild sudo less +ENV HOME /src +WORKDIR /src/kasmvncserver + +RUN adduser --disabled-password docker +RUN adduser docker abuild +RUN echo "docker ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + +RUN apk add rsync binutils + +USER docker diff --git a/alpine/build b/alpine/build new file mode 100755 index 0000000..0658148 --- /dev/null +++ b/alpine/build @@ -0,0 +1 @@ +docker build -f alpine-devenv.dockerfile -t alpine-devenv . diff --git a/alpine/kasmvncserver/APKBUILD b/alpine/kasmvncserver/APKBUILD new file mode 100644 index 0000000..f3fa72c --- /dev/null +++ b/alpine/kasmvncserver/APKBUILD @@ -0,0 +1,101 @@ +#!/bin/bash + +# Contributor: +# Maintainer: Kasm Technologies LLC +pkgname=kasmvncserver +pkgver=1.3.3 +pkgrel=0 +pkgdesc="foo" +url="https://github.com/kasmtech/KasmVNC" +arch="x86_64" +license="GPL-2.0-or-later" +depends=" + libgomp + libjpeg-turbo + libwebp + libxfont2 + libxshmfence + mesa-gbm + pciutils-libs + perl + perl-datetime + perl-hash-merge-simple + perl-list-moreutils + perl-switch + perl-try-tiny + perl-yaml-tiny + perl-datetime + perl-datetime-timezone + pixman + py3-xdg + setxkbmap + xauth + xf86-video-amdgpu + xf86-video-ati + xf86-video-nouveau + xf86-video-intel + xkbcomp + xkeyboard-config + xterm + bash + " +makedepends=" + rsync + binutils + mesa-gl + libxcursor + " +checkdepends="" +install="" +subpackages="" +source="" +builddir="$srcdir/" + + +build() { + tar -xzf ../kasmvnc.alpine_321_x86_64.tgz -C "$srcdir"; +} + +check() { + # Replace with proper check command(s). + # Remove and add !check option if there is no check command. + : +} + +package() { + export SRC="$srcdir/usr/local"; + export SRC_BIN="$SRC/bin"; + export DESTDIR="$pkgdir"; + export DST_MAN="$DESTDIR/usr/share/man/man1"; + + # Replace with proper package command(s) + echo "woo"; + echo "D: $DESTDIR"; + + echo "installing files"; + mkdir -p $pkgdir/usr/bin $pkgdir/usr/lib \ + $pkgdir/usr/share/perl5/vendor_perl $pkgdir/etc/kasmvnc; +#$pkgdir/usr/share/man/man1 \ +#$pkgdir/usr/share/doc/kasmvncserver + cp $SRC_BIN/Xvnc $pkgdir/usr/bin/Xkasmvnc; + cd $pkgdir/usr/bin/ && ln -s Xkasmvnc Xvnc; + cp $SRC_BIN/vncserver $pkgdir/usr/bin/kasmvncserver; + cd $pkgdir/usr/bin/ && ln -s kasmvncserver vncserver; + cp -r $SRC_BIN/KasmVNC $pkgdir/usr/share/perl5/vendor_perl; + cp $SRC_BIN/vncconfig $pkgdir/usr/bin/kasmvncconfig; + cp $SRC_BIN/kasmvncpasswd $pkgdir/usr/bin/; + cd $pkgdir/usr/bin/ && ln -s kasmvncpasswd vncpasswd; + cp $SRC_BIN/kasmxproxy $pkgdir/usr/bin/; + cp -r $SRC/lib/kasmvnc/ $pkgdir/usr/lib/kasmvncserver; + #cp -r $SRC/share/doc/kasmvnc*/* $pkgdir/usr/share/doc/kasmvncserver/ + rsync -r --links --safe-links --exclude '.git*' --exclude po2js \ + --exclude xgettext-html --exclude www/utils/ --exclude .eslintrc \ + $SRC/share/kasmvnc $pkgdir/usr/share; + sed -e 's/^\([^#]\)/# \1/' $SRC/share/kasmvnc/kasmvnc_defaults.yaml > \ + $pkgdir/etc/kasmvnc/kasmvnc.yaml; + # cp $SRC/man/man1/Xvnc.1 $pkgdir/usr/share/man/man1/Xkasmvnc.1 + # cp $SRC/share/man/man1/vncserver.1 $DST_MAN/kasmvncserver.1 + # cp $SRC/share/man/man1/kasmxproxy.1 $DST_MAN/kasmxproxy.1 + # cp $SRC/share/man/man1/vncpasswd.1 $DST_MAN/kasmvncpasswd.1 + # cp $SRC/share/man/man1/vncconfig.1 $DST_MAN/kasmvncconfig.1 +} From ce945d5a1deed74fb77abf4eeee66926dec760a1 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Wed, 26 Feb 2025 17:30:04 +1300 Subject: [PATCH 012/167] KASM-6904 Alpine: add certificate support --- alpine/kasmvncserver/APKBUILD | 9 +++++-- .../kasmvncserver.post-deinstall | 3 +++ .../kasmvncserver/kasmvncserver.post-install | 26 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100755 alpine/kasmvncserver/kasmvncserver.post-deinstall create mode 100755 alpine/kasmvncserver/kasmvncserver.post-install diff --git a/alpine/kasmvncserver/APKBUILD b/alpine/kasmvncserver/APKBUILD index f3fa72c..52b08c3 100644 --- a/alpine/kasmvncserver/APKBUILD +++ b/alpine/kasmvncserver/APKBUILD @@ -10,11 +10,13 @@ url="https://github.com/kasmtech/KasmVNC" arch="x86_64" license="GPL-2.0-or-later" depends=" + bash libgomp libjpeg-turbo libwebp libxfont2 libxshmfence + mcookie mesa-gbm pciutils-libs perl @@ -37,7 +39,6 @@ depends=" xkbcomp xkeyboard-config xterm - bash " makedepends=" rsync @@ -46,7 +47,7 @@ makedepends=" libxcursor " checkdepends="" -install="" +install="$pkgname.post-install $pkgname.post-deinstall" subpackages="" source="" builddir="$srcdir/" @@ -91,6 +92,10 @@ package() { rsync -r --links --safe-links --exclude '.git*' --exclude po2js \ --exclude xgettext-html --exclude www/utils/ --exclude .eslintrc \ $SRC/share/kasmvnc $pkgdir/usr/share; + sed -i -e 's!pem_certificate: .\+$!pem_certificate: /etc/ssl/private/kasmvnc.pem!' \ + $DESTDIR/usr/share/kasmvnc/kasmvnc_defaults.yaml + sed -i -e 's!pem_key: .\+$!pem_key: /etc/ssl/private/kasmvnc.pem!' \ + $DESTDIR/usr/share/kasmvnc/kasmvnc_defaults.yaml sed -e 's/^\([^#]\)/# \1/' $SRC/share/kasmvnc/kasmvnc_defaults.yaml > \ $pkgdir/etc/kasmvnc/kasmvnc.yaml; # cp $SRC/man/man1/Xvnc.1 $pkgdir/usr/share/man/man1/Xkasmvnc.1 diff --git a/alpine/kasmvncserver/kasmvncserver.post-deinstall b/alpine/kasmvncserver/kasmvncserver.post-deinstall new file mode 100755 index 0000000..b30760c --- /dev/null +++ b/alpine/kasmvncserver/kasmvncserver.post-deinstall @@ -0,0 +1,3 @@ +#!/bin/sh + +rm -f /etc/ssl/private/kasmvnc.pem diff --git a/alpine/kasmvncserver/kasmvncserver.post-install b/alpine/kasmvncserver/kasmvncserver.post-install new file mode 100755 index 0000000..1d9f546 --- /dev/null +++ b/alpine/kasmvncserver/kasmvncserver.post-install @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +kasmvnc_group="kasmvnc-cert" + +create_kasmvnc_group() { + if ! getent group "$kasmvnc_group" >/dev/null; then + addgroup --system "$kasmvnc_group" + fi +} + +make_self_signed_certificate() { + local cert_file=/etc/ssl/private/kasmvnc.pem + [ -f "$cert_file" ] && return 0 + + openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \ + -keyout "$cert_file" \ + -out "$cert_file" -subj \ + "/C=US/ST=VA/L=None/O=None/OU=DoFu/CN=kasm/emailAddress=none@none.none" + chgrp "$kasmvnc_group" "$cert_file" + chmod 640 "$cert_file" +} + +create_kasmvnc_group +make_self_signed_certificate From 44ef733f93787707003449388fd8e558aa73fd2d Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Wed, 26 Feb 2025 17:47:45 +1300 Subject: [PATCH 013/167] KASM-6904 Alpine: add -doc package --- alpine/kasmvncserver/APKBUILD | 36 ++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/alpine/kasmvncserver/APKBUILD b/alpine/kasmvncserver/APKBUILD index 52b08c3..b29b098 100644 --- a/alpine/kasmvncserver/APKBUILD +++ b/alpine/kasmvncserver/APKBUILD @@ -45,10 +45,11 @@ makedepends=" binutils mesa-gl libxcursor + gzip " checkdepends="" install="$pkgname.post-install $pkgname.post-deinstall" -subpackages="" +subpackages="$pkgname-doc" source="" builddir="$srcdir/" @@ -69,15 +70,9 @@ package() { export DESTDIR="$pkgdir"; export DST_MAN="$DESTDIR/usr/share/man/man1"; - # Replace with proper package command(s) - echo "woo"; - echo "D: $DESTDIR"; - echo "installing files"; mkdir -p $pkgdir/usr/bin $pkgdir/usr/lib \ $pkgdir/usr/share/perl5/vendor_perl $pkgdir/etc/kasmvnc; -#$pkgdir/usr/share/man/man1 \ -#$pkgdir/usr/share/doc/kasmvncserver cp $SRC_BIN/Xvnc $pkgdir/usr/bin/Xkasmvnc; cd $pkgdir/usr/bin/ && ln -s Xkasmvnc Xvnc; cp $SRC_BIN/vncserver $pkgdir/usr/bin/kasmvncserver; @@ -88,7 +83,6 @@ package() { cd $pkgdir/usr/bin/ && ln -s kasmvncpasswd vncpasswd; cp $SRC_BIN/kasmxproxy $pkgdir/usr/bin/; cp -r $SRC/lib/kasmvnc/ $pkgdir/usr/lib/kasmvncserver; - #cp -r $SRC/share/doc/kasmvnc*/* $pkgdir/usr/share/doc/kasmvncserver/ rsync -r --links --safe-links --exclude '.git*' --exclude po2js \ --exclude xgettext-html --exclude www/utils/ --exclude .eslintrc \ $SRC/share/kasmvnc $pkgdir/usr/share; @@ -98,9 +92,25 @@ package() { $DESTDIR/usr/share/kasmvnc/kasmvnc_defaults.yaml sed -e 's/^\([^#]\)/# \1/' $SRC/share/kasmvnc/kasmvnc_defaults.yaml > \ $pkgdir/etc/kasmvnc/kasmvnc.yaml; - # cp $SRC/man/man1/Xvnc.1 $pkgdir/usr/share/man/man1/Xkasmvnc.1 - # cp $SRC/share/man/man1/vncserver.1 $DST_MAN/kasmvncserver.1 - # cp $SRC/share/man/man1/kasmxproxy.1 $DST_MAN/kasmxproxy.1 - # cp $SRC/share/man/man1/vncpasswd.1 $DST_MAN/kasmvncpasswd.1 - # cp $SRC/share/man/man1/vncconfig.1 $DST_MAN/kasmvncconfig.1 +} + +doc() { + set -e + export SRC="$srcdir/usr/local"; + export SRC_BIN="$SRC/bin"; + export DESTDIR="$subpkgdir"; + export DST_MAN="$DESTDIR/usr/share/man/man1"; + + mkdir -p $subpkgdir/usr/share/man/man1 \ + $subpkgdir/usr/share/doc/kasmvncserver + cp -r $SRC/share/doc/kasmvnc*/* $subpkgdir/usr/share/doc/kasmvncserver/ + cp $SRC/man/man1/Xvnc.1 $subpkgdir/usr/share/man/man1/Xkasmvnc.1 + cp $SRC/share/man/man1/vncserver.1 $DST_MAN/kasmvncserver.1 + cp $SRC/share/man/man1/kasmxproxy.1 $DST_MAN/kasmxproxy.1 + cp $SRC/share/man/man1/vncpasswd.1 $DST_MAN/kasmvncpasswd.1 + cp $SRC/share/man/man1/vncconfig.1 $DST_MAN/kasmvncconfig.1 + gzip -9 $DST_MAN/* + cd $DST_MAN && ln -s Xkasmvnc.1.gz Xvnc.1.gz && \ + ln -s kasmvncserver.1.gz vncserver.1.gz && \ + ln -s kasmvncpasswd.1.gz vncpasswd.1.gz } From de99c920972b81a5b0e875bd9bc7c4b098eabfe6 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Wed, 26 Feb 2025 17:50:14 +1300 Subject: [PATCH 014/167] KASM-6904 Alpine: add package description --- alpine/kasmvncserver/APKBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alpine/kasmvncserver/APKBUILD b/alpine/kasmvncserver/APKBUILD index b29b098..1d4a256 100644 --- a/alpine/kasmvncserver/APKBUILD +++ b/alpine/kasmvncserver/APKBUILD @@ -5,7 +5,7 @@ pkgname=kasmvncserver pkgver=1.3.3 pkgrel=0 -pkgdesc="foo" +pkgdesc="KasmVNC provides remote web-based access to a Desktop or application." url="https://github.com/kasmtech/KasmVNC" arch="x86_64" license="GPL-2.0-or-later" From 8343f4a02a73a03e230b2a43550a79b465da94d1 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Thu, 27 Feb 2025 15:27:37 +1300 Subject: [PATCH 015/167] KASM-6904 Alpine: add openssl dependency --- alpine/kasmvncserver/APKBUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/alpine/kasmvncserver/APKBUILD b/alpine/kasmvncserver/APKBUILD index 1d4a256..bf74e65 100644 --- a/alpine/kasmvncserver/APKBUILD +++ b/alpine/kasmvncserver/APKBUILD @@ -18,6 +18,7 @@ depends=" libxshmfence mcookie mesa-gbm + openssl pciutils-libs perl perl-datetime From f062e9727a983a4a07f741f515285632df35a192 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Thu, 27 Feb 2025 15:35:15 +1300 Subject: [PATCH 016/167] KASM-6904 Alpine: remove redundant code --- alpine/alpine-devenv.dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/alpine/alpine-devenv.dockerfile b/alpine/alpine-devenv.dockerfile index 89d42f8..63e2bff 100644 --- a/alpine/alpine-devenv.dockerfile +++ b/alpine/alpine-devenv.dockerfile @@ -8,6 +8,4 @@ RUN adduser --disabled-password docker RUN adduser docker abuild RUN echo "docker ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers -RUN apk add rsync binutils - USER docker From 232e97a8926567965db6ca5e8bc9aa79afa7dea6 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Thu, 27 Feb 2025 22:35:56 +1300 Subject: [PATCH 017/167] KASM-6904 Alpine: update 3.21 pipeline to build apk --- alpine/kasmvncserver/APKBUILD | 3 ++- builder/build-apk | 2 ++ builder/build-apk-inside-docker | 6 ++++-- builder/dockerfile.alpine_321.apk.build | 6 ++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/alpine/kasmvncserver/APKBUILD b/alpine/kasmvncserver/APKBUILD index bf74e65..46135e4 100644 --- a/alpine/kasmvncserver/APKBUILD +++ b/alpine/kasmvncserver/APKBUILD @@ -56,7 +56,8 @@ builddir="$srcdir/" build() { - tar -xzf ../kasmvnc.alpine_321_x86_64.tgz -C "$srcdir"; + local alpine_version=$(cat /etc/alpine-release | awk -F. '{ print $1$2 }') + tar -xzf "/src/builder/build/kasmvnc.alpine_$alpine_version.tar.gz" -C "$srcdir"; } check() { diff --git a/builder/build-apk b/builder/build-apk index 73fa677..b790d57 100755 --- a/builder/build-apk +++ b/builder/build-apk @@ -12,6 +12,8 @@ docker build -t kasmvnc_apkbuilder_${os}:${os_codename} -f \ source_dir=$(echo $PWD) L_UID=$(id -u) L_GID=$(id -g) +ABUILD_GID=300 docker run --rm -v "$source_dir":/src --user $L_UID:$L_GID \ + --group-add $ABUILD_GID \ kasmvnc_apkbuilder_${os}:${os_codename} /bin/bash -c \ '/src/builder/build-apk-inside-docker' diff --git a/builder/build-apk-inside-docker b/builder/build-apk-inside-docker index 08617f7..ad7acc6 100755 --- a/builder/build-apk-inside-docker +++ b/builder/build-apk-inside-docker @@ -4,8 +4,10 @@ set -e os=alpine os_codename=$(cat /etc/os-release | awk '/VERSION_ID/' | grep -o '[[:digit:]]' | tr -d '\n' | head -c 3) +apkbuild_dir=/src/alpine/kasmvncserver/ + +cd "$apkbuild_dir" && abuild -r mkdir -p /src/builder/build/${os}_${os_codename} mv \ - /src/builder/build/kasmvnc.${os}_${os_codename}.tar.gz \ - /src/builder/build/${os}_${os_codename}/kasmvnc.${os}_${os_codename}_$(uname -m).tgz + /src/alpine/packages/alpine/x86_64/*.apk /src/builder/build/${os}_${os_codename}/ diff --git a/builder/dockerfile.alpine_321.apk.build b/builder/dockerfile.alpine_321.apk.build index b67ef79..a6c5867 100644 --- a/builder/dockerfile.alpine_321.apk.build +++ b/builder/dockerfile.alpine_321.apk.build @@ -1,6 +1,12 @@ FROM alpine:3.21 RUN apk add shadow bash +RUN apk add abuild sudo less + +ENV HOME /src/alpine +WORKDIR $HOME/kasmvncserver + +COPY alpine/.abuild/*.pub /etc/apk/keys/ RUN useradd -m docker && echo "docker:docker" | chpasswd From dd841cc0e636b85245dd5b187fde0e8d3d571117 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Mon, 3 Mar 2025 12:19:17 +1300 Subject: [PATCH 018/167] KASM-6904 Alpine: add signing key via env vars --- alpine/.abuild/abuild.conf | 2 ++ builder/build-apk | 20 ++++++++++++++++---- builder/dockerfile.alpine_321.apk.build | 8 +++++++- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 alpine/.abuild/abuild.conf diff --git a/alpine/.abuild/abuild.conf b/alpine/.abuild/abuild.conf new file mode 100644 index 0000000..4be7a96 --- /dev/null +++ b/alpine/.abuild/abuild.conf @@ -0,0 +1,2 @@ +PACKAGER="Kasm Technologies LLC " +PACKAGER_PRIVKEY="/src/alpine/.abuild/kasmvnc_signing_key.rsa" diff --git a/builder/build-apk b/builder/build-apk index b790d57..00ead77 100755 --- a/builder/build-apk +++ b/builder/build-apk @@ -2,17 +2,29 @@ set -e +copy_signing_key_to_user_abuild_dir() { + docker run --rm -v $PWD/alpine/.abuild:/abuild --user $L_UID:$L_GID \ + $builder_image \ + cp /etc/apk/keys/kasmvnc_signing_key.rsa.pub \ + /etc/apk/keys/kasmvnc_signing_key.rsa /abuild +} + . builder/os_ver_cli.sh cd "$(dirname "$0")/.." -docker build -t kasmvnc_apkbuilder_${os}:${os_codename} -f \ - builder/dockerfile.${os}_${os_codename}.apk.build . - -source_dir=$(echo $PWD) L_UID=$(id -u) L_GID=$(id -g) ABUILD_GID=300 + +builder_image=kasmvnc_apkbuilder_${os}:${os_codename} +docker build -t $builder_image \ + --build-arg KASMVNC_ALPINE_PRIVATE_KEY \ + --build-arg KASMVNC_ALPINE_PUBLIC_KEY \ + -f builder/dockerfile.${os}_${os_codename}.apk.build . +copy_signing_key_to_user_abuild_dir + +source_dir=$(echo $PWD) docker run --rm -v "$source_dir":/src --user $L_UID:$L_GID \ --group-add $ABUILD_GID \ kasmvnc_apkbuilder_${os}:${os_codename} /bin/bash -c \ diff --git a/builder/dockerfile.alpine_321.apk.build b/builder/dockerfile.alpine_321.apk.build index a6c5867..8771f31 100644 --- a/builder/dockerfile.alpine_321.apk.build +++ b/builder/dockerfile.alpine_321.apk.build @@ -6,7 +6,13 @@ RUN apk add abuild sudo less ENV HOME /src/alpine WORKDIR $HOME/kasmvncserver -COPY alpine/.abuild/*.pub /etc/apk/keys/ +ARG KASMVNC_ALPINE_PRIVATE_KEY +ARG KASMVNC_ALPINE_PUBLIC_KEY +ENV APK_KEYS_DIR=/etc/apk/keys +RUN echo -n "$KASMVNC_ALPINE_PRIVATE_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa +RUN echo -n "$KASMVNC_ALPINE_PUBLIC_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub RUN useradd -m docker && echo "docker:docker" | chpasswd From 628039aed3ea98990fdd5e5cfc69202138b9a1f7 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 3 Mar 2025 12:58:05 +0000 Subject: [PATCH 019/167] added dev container for building kasmvnc --- .gitignore | 5 +++++ BUILDING.txt | 26 ++++++++++++++++++++++++++ CMakeLists.txt | 2 +- builder/dockerfile.ubuntu_jammy.dev | 25 +++++++++++++++++++++++++ builder/scripts/build-libjpeg-turbo | 1 + builder/scripts/build-webp | 20 ++++++++++++++------ 6 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 builder/dockerfile.ubuntu_jammy.dev diff --git a/.gitignore b/.gitignore index f4a278e..bc7e8b5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.lo .deps .libs +*.swp CMakeFiles CMakeCache.txt @@ -12,6 +13,10 @@ Makefile Makefile.in config.h +libjpeg-turbo/ +xorg.build/ +install_manifest.txt + builder/build/ builder/www/ spec/tmp diff --git a/BUILDING.txt b/BUILDING.txt index b0f3782..45b5f3f 100644 --- a/BUILDING.txt +++ b/BUILDING.txt @@ -71,6 +71,32 @@ For in-tree builds, these directories are the same. Building KasmVNC ================= +Building the KasmVNC Server using Docker +---------------------------------------- + +```bash +git submodule init +git submodule update --remote --merge +sudo docker build -t kasmvnc:dev -f builder/dockerfile.ubuntu_jammy.dev . +sudo docker run -it -v ./:/src -p 6901:6901 kasmvnc:dev +``` + +Now from inside the container. + +```bash +kasm-user@5c2802e4cf1e:/src$ sudo builder/scripts/build-webp +kasm-user@5c2802e4cf1e:/src$ sudo builder/scripts/build-build-libjpeg-turbo +kasm-user@5c2802e4cf1e:/src$ builder/build.sh +``` + +Now run Xvnc and Xfce4 from inside the container + +```bash +/src/xorg.build/bin/Xvnc -interface 0.0.0.0 -PublicIP 127.0.0.1 -disableBasicAuth -RectThreads 0 -Log *:stdout:100 -httpd /src/kasmweb/dist -sslOnly 0 -SecurityTypes None -websocketPort 6901 :1 +/usr/bin/xfce4-session --display :1 +``` + +Now open a browser and navigate to your dev VM on port 6901. Building the KasmVNC Server on Modern Unix/Linux Systems --------------------------------------------------------- diff --git a/CMakeLists.txt b/CMakeLists.txt index 3807fc4..1c3bded 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -245,7 +245,7 @@ if(ENABLE_NLS) add_subdirectory(po) endif() -add_subdirectory(tests) +####add_subdirectory(tests) include(cmake/BuildPackages.cmake) diff --git a/builder/dockerfile.ubuntu_jammy.dev b/builder/dockerfile.ubuntu_jammy.dev new file mode 100644 index 0000000..d13638d --- /dev/null +++ b/builder/dockerfile.ubuntu_jammy.dev @@ -0,0 +1,25 @@ +FROM kasmweb/ubuntu-jammy-desktop:develop + +ENV KASMVNC_BUILD_OS ubuntu +ENV KASMVNC_BUILD_OS_CODENAME jammy +ENV XORG_VER 21.1.3 +ENV XORG_PATCH 21 +ENV DEBIAN_FRONTEND noninteractive + +EXPOSE 6901 + +USER root + +RUN sed -i 's$# deb-src$deb-src$' /etc/apt/sources.list && \ + apt update && \ + apt install -y socat sudo libxfont-dev cmake git libgnutls28-dev vim wget tightvncserver curl libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev pkg-config libfreetype6-dev libxtst-dev autoconf automake libtool xutils-dev libpixman-1-dev libxshmfence-dev libxcvt-dev libxkbfile-dev x11proto-dev libgbm-dev inotify-tools && \ + echo "kasm-user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + +RUN curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - +RUN apt install -y nodejs + +USER 1000 + +WORKDIR /src + +ENTRYPOINT /bin/bash diff --git a/builder/scripts/build-libjpeg-turbo b/builder/scripts/build-libjpeg-turbo index 1510f24..13d1f3f 100755 --- a/builder/scripts/build-libjpeg-turbo +++ b/builder/scripts/build-libjpeg-turbo @@ -22,6 +22,7 @@ ensure_libjpeg_is_fast() { prepare_libjpeg_source() { export JPEG_TURBO_RELEASE=$(curl -sX GET "https://api.github.com/repos/libjpeg-turbo/libjpeg-turbo/releases/latest" \ | awk '/tag_name/{print $4;exit}' FS='[""]') + [ -d ./libjpeg-turbo ] && rm -rf ./libjpeg-turbo mkdir libjpeg-turbo curl -Ls "https://github.com/libjpeg-turbo/libjpeg-turbo/archive/${JPEG_TURBO_RELEASE}.tar.gz" | \ tar xzvf - -C libjpeg-turbo/ --strip-components=1 diff --git a/builder/scripts/build-webp b/builder/scripts/build-webp index 82b07ba..a6b2fd0 100755 --- a/builder/scripts/build-webp +++ b/builder/scripts/build-webp @@ -2,18 +2,25 @@ set -euo pipefail -webp_tar_url=https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.2.4.tar.gz +WEBP_VERSION="1.2.4" +WEBP_TAR_URL="https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-${WEBP_VERSION}.tar.gz" +WEBP_TAR_FILE="/tmp/libwebp-${WEBP_VERSION}.tar.gz" +WEBP_SRC_DIR="/tmp/libwebp-${WEBP_VERSION}" prepare_source() { cd /tmp - wget "$webp_tar_url" - tar -xzf /tmp/libwebp-* - rm /tmp/libwebp-*.tar.gz - cd /tmp/libwebp-* + + # Remove old files if they exist + [ -f "$WEBP_TAR_FILE" ] && rm "$WEBP_TAR_FILE" + [ -d "$WEBP_SRC_DIR" ] && rm -rf "$WEBP_SRC_DIR" + + wget "$WEBP_TAR_URL" + tar -xzf "$WEBP_TAR_FILE" + cd "$WEBP_SRC_DIR" } build_and_install() { - export MAKEFLAGS=-j`nproc` + export MAKEFLAGS=-j$(nproc) ./configure --enable-static --disable-shared make make install @@ -21,3 +28,4 @@ build_and_install() { prepare_source build_and_install + From 3182b902d2a19ab1a5e807e3f53e1e1ddf78f921 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 3 Mar 2025 13:14:11 +0000 Subject: [PATCH 020/167] updates to build instructions --- BUILDING.txt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/BUILDING.txt b/BUILDING.txt index 45b5f3f..85918e5 100644 --- a/BUILDING.txt +++ b/BUILDING.txt @@ -84,15 +84,22 @@ sudo docker run -it -v ./:/src -p 6901:6901 kasmvnc:dev Now from inside the container. ```bash -kasm-user@5c2802e4cf1e:/src$ sudo builder/scripts/build-webp -kasm-user@5c2802e4cf1e:/src$ sudo builder/scripts/build-build-libjpeg-turbo -kasm-user@5c2802e4cf1e:/src$ builder/build.sh +# build frontend +cd kasmweb +npm install +npm run build # <-- only run this on subsequent changes to front-end code +cd .. +# build dependencies +sudo builder/scripts/build-webp +sudo builder/scripts/build-build-libjpeg-turbo +# Build KasmVNC +builder/build.sh ``` Now run Xvnc and Xfce4 from inside the container ```bash -/src/xorg.build/bin/Xvnc -interface 0.0.0.0 -PublicIP 127.0.0.1 -disableBasicAuth -RectThreads 0 -Log *:stdout:100 -httpd /src/kasmweb/dist -sslOnly 0 -SecurityTypes None -websocketPort 6901 :1 +/src/xorg.build/bin/Xvnc -interface 0.0.0.0 -PublicIP 127.0.0.1 -disableBasicAuth -RectThreads 0 -Log *:stdout:100 -httpd /src/kasmweb/dist -sslOnly 0 -SecurityTypes None -websocketPort 6901 :1 & /usr/bin/xfce4-session --display :1 ``` From c3a3d67cdf3be7712038ab0453a870b6e23fe7a9 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Tue, 4 Mar 2025 17:58:14 +1300 Subject: [PATCH 021/167] KASM-6904 Alpine: add arm support --- alpine/kasmvncserver/APKBUILD | 2 +- builder/build-apk-inside-docker | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/alpine/kasmvncserver/APKBUILD b/alpine/kasmvncserver/APKBUILD index 46135e4..3138c47 100644 --- a/alpine/kasmvncserver/APKBUILD +++ b/alpine/kasmvncserver/APKBUILD @@ -7,7 +7,7 @@ pkgver=1.3.3 pkgrel=0 pkgdesc="KasmVNC provides remote web-based access to a Desktop or application." url="https://github.com/kasmtech/KasmVNC" -arch="x86_64" +arch="x86_64 aarch64" license="GPL-2.0-or-later" depends=" bash diff --git a/builder/build-apk-inside-docker b/builder/build-apk-inside-docker index ad7acc6..f06d9e8 100755 --- a/builder/build-apk-inside-docker +++ b/builder/build-apk-inside-docker @@ -10,4 +10,4 @@ cd "$apkbuild_dir" && abuild -r mkdir -p /src/builder/build/${os}_${os_codename} mv \ - /src/alpine/packages/alpine/x86_64/*.apk /src/builder/build/${os}_${os_codename}/ + /src/alpine/packages/alpine/$(arch)/*.apk /src/builder/build/${os}_${os_codename}/ From 45f9f8d3b32733306a302a795e5d083ae3c42db8 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Tue, 4 Mar 2025 20:19:32 +1300 Subject: [PATCH 022/167] KASM-6904 Alpine: 3.20 apk package support --- builder/dockerfile.alpine_320.apk.build | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/builder/dockerfile.alpine_320.apk.build b/builder/dockerfile.alpine_320.apk.build index d99e67e..515d825 100644 --- a/builder/dockerfile.alpine_320.apk.build +++ b/builder/dockerfile.alpine_320.apk.build @@ -1,6 +1,18 @@ FROM alpine:3.20 RUN apk add shadow bash +RUN apk add abuild sudo less + +ENV HOME /src/alpine +WORKDIR $HOME/kasmvncserver + +ARG KASMVNC_ALPINE_PRIVATE_KEY +ARG KASMVNC_ALPINE_PUBLIC_KEY +ENV APK_KEYS_DIR=/etc/apk/keys +RUN echo -n "$KASMVNC_ALPINE_PRIVATE_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa +RUN echo -n "$KASMVNC_ALPINE_PUBLIC_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub RUN useradd -m docker && echo "docker:docker" | chpasswd From 0c2e88c4597d8de14e69cdcc5893a15b2c9b3234 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Tue, 4 Mar 2025 20:54:08 +1300 Subject: [PATCH 023/167] KASM-6904 Alpine: 3.19 apk package support --- builder/dockerfile.alpine_319.apk.build | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/builder/dockerfile.alpine_319.apk.build b/builder/dockerfile.alpine_319.apk.build index a0930b4..7771b48 100644 --- a/builder/dockerfile.alpine_319.apk.build +++ b/builder/dockerfile.alpine_319.apk.build @@ -1,6 +1,18 @@ FROM alpine:3.19 RUN apk add shadow bash +RUN apk add abuild sudo less + +ENV HOME /src/alpine +WORKDIR $HOME/kasmvncserver + +ARG KASMVNC_ALPINE_PRIVATE_KEY +ARG KASMVNC_ALPINE_PUBLIC_KEY +ENV APK_KEYS_DIR=/etc/apk/keys +RUN echo -n "$KASMVNC_ALPINE_PRIVATE_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa +RUN echo -n "$KASMVNC_ALPINE_PUBLIC_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub RUN useradd -m docker && echo "docker:docker" | chpasswd From ebfe61392aa4838d23ae18841f2e7368530755a4 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Wed, 5 Mar 2025 14:45:55 +1300 Subject: [PATCH 024/167] KASM-6904 Alpine: 3.18 apk package support --- builder/dockerfile.alpine_318.apk.build | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/builder/dockerfile.alpine_318.apk.build b/builder/dockerfile.alpine_318.apk.build index 9504897..209e142 100644 --- a/builder/dockerfile.alpine_318.apk.build +++ b/builder/dockerfile.alpine_318.apk.build @@ -1,6 +1,18 @@ FROM alpine:3.18 RUN apk add shadow bash +RUN apk add abuild sudo less + +ENV HOME /src/alpine +WORKDIR $HOME/kasmvncserver + +ARG KASMVNC_ALPINE_PRIVATE_KEY +ARG KASMVNC_ALPINE_PUBLIC_KEY +ENV APK_KEYS_DIR=/etc/apk/keys +RUN echo -n "$KASMVNC_ALPINE_PRIVATE_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa +RUN echo -n "$KASMVNC_ALPINE_PUBLIC_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub RUN useradd -m docker && echo "docker:docker" | chpasswd From b6cc920ba5b39cfe1693865db7076cb1c1f8f86d Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Wed, 5 Mar 2025 15:00:49 +1300 Subject: [PATCH 025/167] KASM-6904 Alpine: 3.17 apk package support --- builder/dockerfile.alpine_317.apk.build | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/builder/dockerfile.alpine_317.apk.build b/builder/dockerfile.alpine_317.apk.build index 732f5f0..fafdecb 100644 --- a/builder/dockerfile.alpine_317.apk.build +++ b/builder/dockerfile.alpine_317.apk.build @@ -1,6 +1,18 @@ FROM alpine:3.17 RUN apk add shadow bash +RUN apk add abuild sudo less + +ENV HOME /src/alpine +WORKDIR $HOME/kasmvncserver + +ARG KASMVNC_ALPINE_PRIVATE_KEY +ARG KASMVNC_ALPINE_PUBLIC_KEY +ENV APK_KEYS_DIR=/etc/apk/keys +RUN echo -n "$KASMVNC_ALPINE_PRIVATE_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa +RUN echo -n "$KASMVNC_ALPINE_PUBLIC_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub RUN useradd -m docker && echo "docker:docker" | chpasswd From 965ea7587a636b2c2b340fb5168d1ea250d1d218 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Wed, 5 Mar 2025 15:08:06 +1300 Subject: [PATCH 026/167] KASM-6904 Fix CI: run abuild as user 1000, not root --- builder/build-apk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/builder/build-apk b/builder/build-apk index 00ead77..e0d6d30 100755 --- a/builder/build-apk +++ b/builder/build-apk @@ -16,6 +16,10 @@ cd "$(dirname "$0")/.." L_UID=$(id -u) L_GID=$(id -g) ABUILD_GID=300 +if [ "$L_UID" = 0 ]; then + L_UID=1000 + L_GID=1000 +fi builder_image=kasmvnc_apkbuilder_${os}:${os_codename} docker build -t $builder_image \ From 2b731e170a65c00a74d4cbc407199afd5b8a132d Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 7 Mar 2025 14:50:20 +1300 Subject: [PATCH 027/167] KASM-6904 Fix CI --- .gitlab-ci.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6dd1bf6..168d21e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -198,7 +198,7 @@ build_ubuntu_noble: artifacts: paths: - output/ - + build_ubuntu_noble_arm: stage: build allow_failure: true @@ -209,7 +209,7 @@ build_ubuntu_noble_arm: - *prepare_www after_script: - *prepare_artfacts - script: + script: - bash builder/build-package ubuntu noble; only: variables: @@ -617,13 +617,13 @@ build_fedora_forty: artifacts: paths: - output/ - + build_fedora_forty_arm: stage: build allow_failure: true tags: - oci-fixed-arm - before_script: + before_script: - *prepare_build - *prepare_www after_script: @@ -655,18 +655,18 @@ build_fedora_fortyone: artifacts: paths: - output/ - + build_fedora_fortyone_arm: stage: build allow_failure: true tags: - oci-fixed-arm - before_script: + before_script: - *prepare_build - *prepare_www after_script: - *prepare_artfacts - script: + script: - bash builder/build-package fedora fortyone; only: variables: @@ -779,6 +779,8 @@ build_alpine_319: artifacts: paths: - output/ + - alpine/.abuild/kasmvnc_signing_key.rsa + - alpine/.abuild/kasmvnc_signing_key.rsa.pub build_alpine_319_arm: stage: build From 259d8953ef619120ed14f52dbbfb464c4669bbcf Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 7 Mar 2025 15:00:56 +1300 Subject: [PATCH 028/167] Revert "KASM-6904 Fix CI" This reverts commit 2b731e170a65c00a74d4cbc407199afd5b8a132d. --- .gitlab-ci.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 168d21e..6dd1bf6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -198,7 +198,7 @@ build_ubuntu_noble: artifacts: paths: - output/ - + build_ubuntu_noble_arm: stage: build allow_failure: true @@ -209,7 +209,7 @@ build_ubuntu_noble_arm: - *prepare_www after_script: - *prepare_artfacts - script: + script: - bash builder/build-package ubuntu noble; only: variables: @@ -617,13 +617,13 @@ build_fedora_forty: artifacts: paths: - output/ - + build_fedora_forty_arm: stage: build allow_failure: true tags: - oci-fixed-arm - before_script: + before_script: - *prepare_build - *prepare_www after_script: @@ -655,18 +655,18 @@ build_fedora_fortyone: artifacts: paths: - output/ - + build_fedora_fortyone_arm: stage: build allow_failure: true tags: - oci-fixed-arm - before_script: + before_script: - *prepare_build - *prepare_www after_script: - *prepare_artfacts - script: + script: - bash builder/build-package fedora fortyone; only: variables: @@ -779,8 +779,6 @@ build_alpine_319: artifacts: paths: - output/ - - alpine/.abuild/kasmvnc_signing_key.rsa - - alpine/.abuild/kasmvnc_signing_key.rsa.pub build_alpine_319_arm: stage: build From aad8725c482c14c5f4fb8f2ac38853bee421648a Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 7 Mar 2025 15:03:20 +1300 Subject: [PATCH 029/167] KASM-6904 Fix CI --- builder/dockerfile.alpine_319.apk.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builder/dockerfile.alpine_319.apk.build b/builder/dockerfile.alpine_319.apk.build index 7771b48..2d4dfdc 100644 --- a/builder/dockerfile.alpine_319.apk.build +++ b/builder/dockerfile.alpine_319.apk.build @@ -11,8 +11,10 @@ ARG KASMVNC_ALPINE_PUBLIC_KEY ENV APK_KEYS_DIR=/etc/apk/keys RUN echo -n "$KASMVNC_ALPINE_PRIVATE_KEY" > \ $APK_KEYS_DIR/kasmvnc_signing_key.rsa +RUN echo KASMVNC_ALPINE_PRIVATE_KEY "$KASMVNC_ALPINE_PRIVATE_KEY" RUN echo -n "$KASMVNC_ALPINE_PUBLIC_KEY" > \ $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub +RUN echo KASMVNC_ALPINE_PUBLIC_KEY "$KASMVNC_ALPINE_PUBLIC_KEY" RUN useradd -m docker && echo "docker:docker" | chpasswd From 2ca875a570185147de1304f1813282cf0959e7b4 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 7 Mar 2025 15:05:28 +1300 Subject: [PATCH 030/167] KASM-6904 Limit build to Alpine 3.19 --- .gitlab-ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6dd1bf6..308e3c8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ variables: # E.g. BUILD_JOBS: build_debian_buster,build_ubuntu_bionic. This will include # arm builds, because build_debian_buster_arm matches build_debian_buster. # "BUILD_JOBS: none" won't build any build jobs, nor www. - BUILD_JOBS: all + BUILD_JOBS: build_alpine_319 DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" @@ -198,7 +198,7 @@ build_ubuntu_noble: artifacts: paths: - output/ - + build_ubuntu_noble_arm: stage: build allow_failure: true @@ -209,7 +209,7 @@ build_ubuntu_noble_arm: - *prepare_www after_script: - *prepare_artfacts - script: + script: - bash builder/build-package ubuntu noble; only: variables: @@ -617,13 +617,13 @@ build_fedora_forty: artifacts: paths: - output/ - + build_fedora_forty_arm: stage: build allow_failure: true tags: - oci-fixed-arm - before_script: + before_script: - *prepare_build - *prepare_www after_script: @@ -655,18 +655,18 @@ build_fedora_fortyone: artifacts: paths: - output/ - + build_fedora_fortyone_arm: stage: build allow_failure: true tags: - oci-fixed-arm - before_script: + before_script: - *prepare_build - *prepare_www after_script: - *prepare_artfacts - script: + script: - bash builder/build-package fedora fortyone; only: variables: From 90351722729fcd783b79abdf45ca9a315dd9facf Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 7 Mar 2025 15:16:43 +1300 Subject: [PATCH 031/167] KASM-6904 CI: .abuild as artifacts --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 308e3c8..abdf519 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -779,6 +779,8 @@ build_alpine_319: artifacts: paths: - output/ + - alpine/.abuild + - when: always build_alpine_319_arm: stage: build From f0bf5fdb40aa3c9c5f0de75f94ef6429ebd5a37b Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 7 Mar 2025 15:18:45 +1300 Subject: [PATCH 032/167] KASM-6904 Fix CI --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index abdf519..8a9fd92 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -780,7 +780,7 @@ build_alpine_319: paths: - output/ - alpine/.abuild - - when: always + - when: always build_alpine_319_arm: stage: build From c73142e589d358e1f3d71d915f88cc6a210fc70e Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 7 Mar 2025 15:25:48 +1300 Subject: [PATCH 033/167] KASM-6904 Fix CI --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8a9fd92..a9fbc7c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -780,7 +780,7 @@ build_alpine_319: paths: - output/ - alpine/.abuild - - when: always + when: always build_alpine_319_arm: stage: build From 179497ddcd0acba42352d8d7db7bb72e6cb03a15 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 7 Mar 2025 16:17:40 +1300 Subject: [PATCH 034/167] KASM-6904 CI: use masked Alpine signing key env var --- builder/dockerfile.alpine_319.apk.build | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/builder/dockerfile.alpine_319.apk.build b/builder/dockerfile.alpine_319.apk.build index 2d4dfdc..fcec8e3 100644 --- a/builder/dockerfile.alpine_319.apk.build +++ b/builder/dockerfile.alpine_319.apk.build @@ -9,8 +9,14 @@ WORKDIR $HOME/kasmvncserver ARG KASMVNC_ALPINE_PRIVATE_KEY ARG KASMVNC_ALPINE_PUBLIC_KEY ENV APK_KEYS_DIR=/etc/apk/keys -RUN echo -n "$KASMVNC_ALPINE_PRIVATE_KEY" > \ - $APK_KEYS_DIR/kasmvnc_signing_key.rsa +ENV BEGIN_PRIVATE_KEY='-----BEGIN PRIVATE KEY-----' +ENV END_PRIVATE_KEY='-----END PRIVATE KEY-----' +RUN if echo "$KASMVNC_ALPINE_PRIVATE_KEY" | grep -q -- "$BEGIN_PRIVATE_KEY"; then \ + echo "$KASMVNC_ALPINE_PRIVATE_KEY" > $APK_KEYS_DIR/kasmvnc_signing_key.rsa; \ + else \ + echo "$BEGIN_PRIVATE_KEY\n$KASMVNC_ALPINE_PRIVATE_KEY\n$END_PRIVATE_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa; \ + fi RUN echo KASMVNC_ALPINE_PRIVATE_KEY "$KASMVNC_ALPINE_PRIVATE_KEY" RUN echo -n "$KASMVNC_ALPINE_PUBLIC_KEY" > \ $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub From cd879fc536f7b27040880f04671b24ef1ff71bc5 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 7 Mar 2025 16:30:59 +1300 Subject: [PATCH 035/167] KASM-6904 Use bash as docker shell in Alpine 3.19 apk build --- builder/dockerfile.alpine_319.apk.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builder/dockerfile.alpine_319.apk.build b/builder/dockerfile.alpine_319.apk.build index fcec8e3..42e3513 100644 --- a/builder/dockerfile.alpine_319.apk.build +++ b/builder/dockerfile.alpine_319.apk.build @@ -3,6 +3,8 @@ FROM alpine:3.19 RUN apk add shadow bash RUN apk add abuild sudo less +SHELL ["/bin/bash", "-c"] + ENV HOME /src/alpine WORKDIR $HOME/kasmvncserver From a2b26eba66e0f35fc16c24735880db2b4c840f08 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 7 Mar 2025 16:37:30 +1300 Subject: [PATCH 036/167] KASM-6904 Fix CI --- builder/dockerfile.alpine_319.apk.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/dockerfile.alpine_319.apk.build b/builder/dockerfile.alpine_319.apk.build index 42e3513..1536c97 100644 --- a/builder/dockerfile.alpine_319.apk.build +++ b/builder/dockerfile.alpine_319.apk.build @@ -16,7 +16,7 @@ ENV END_PRIVATE_KEY='-----END PRIVATE KEY-----' RUN if echo "$KASMVNC_ALPINE_PRIVATE_KEY" | grep -q -- "$BEGIN_PRIVATE_KEY"; then \ echo "$KASMVNC_ALPINE_PRIVATE_KEY" > $APK_KEYS_DIR/kasmvnc_signing_key.rsa; \ else \ - echo "$BEGIN_PRIVATE_KEY\n$KASMVNC_ALPINE_PRIVATE_KEY\n$END_PRIVATE_KEY" > \ + echo -e "$BEGIN_PRIVATE_KEY\n$KASMVNC_ALPINE_PRIVATE_KEY\n$END_PRIVATE_KEY" > \ $APK_KEYS_DIR/kasmvnc_signing_key.rsa; \ fi RUN echo KASMVNC_ALPINE_PRIVATE_KEY "$KASMVNC_ALPINE_PRIVATE_KEY" From 5435696dc7ed9d9723dd16a6d1ab6a2033090edf Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sat, 8 Mar 2025 17:19:11 +1300 Subject: [PATCH 037/167] KASM-6904 Print env --- builder/dockerfile.alpine_319.apk.build | 1 + 1 file changed, 1 insertion(+) diff --git a/builder/dockerfile.alpine_319.apk.build b/builder/dockerfile.alpine_319.apk.build index 1536c97..699ddbd 100644 --- a/builder/dockerfile.alpine_319.apk.build +++ b/builder/dockerfile.alpine_319.apk.build @@ -23,6 +23,7 @@ RUN echo KASMVNC_ALPINE_PRIVATE_KEY "$KASMVNC_ALPINE_PRIVATE_KEY" RUN echo -n "$KASMVNC_ALPINE_PUBLIC_KEY" > \ $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub RUN echo KASMVNC_ALPINE_PUBLIC_KEY "$KASMVNC_ALPINE_PUBLIC_KEY" +RUN env RUN useradd -m docker && echo "docker:docker" | chpasswd From be265fa9ee4396cd8ac25473341393b7eb3036ae Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sat, 8 Mar 2025 17:25:43 +1300 Subject: [PATCH 038/167] KASM-6904 Print env --- builder/build-apk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builder/build-apk b/builder/build-apk index e0d6d30..19f8f27 100755 --- a/builder/build-apk +++ b/builder/build-apk @@ -21,6 +21,8 @@ if [ "$L_UID" = 0 ]; then L_GID=1000 fi +echo "woo" +env builder_image=kasmvnc_apkbuilder_${os}:${os_codename} docker build -t $builder_image \ --build-arg KASMVNC_ALPINE_PRIVATE_KEY \ From 950d358af9891637269a89e1a7b53505c492b4fd Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 16:08:19 +1300 Subject: [PATCH 039/167] KASM-6904 Fix CI --- builder/dockerfile.alpine_319.apk.build | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/builder/dockerfile.alpine_319.apk.build b/builder/dockerfile.alpine_319.apk.build index 699ddbd..2c60fef 100644 --- a/builder/dockerfile.alpine_319.apk.build +++ b/builder/dockerfile.alpine_319.apk.build @@ -13,6 +13,8 @@ ARG KASMVNC_ALPINE_PUBLIC_KEY ENV APK_KEYS_DIR=/etc/apk/keys ENV BEGIN_PRIVATE_KEY='-----BEGIN PRIVATE KEY-----' ENV END_PRIVATE_KEY='-----END PRIVATE KEY-----' +ENV BEGIN_PUBLIC_KEY='-----BEGIN PUBLIC KEY-----' +ENV END_PUBLIC_KEY='-----END PUBLIC KEY-----' RUN if echo "$KASMVNC_ALPINE_PRIVATE_KEY" | grep -q -- "$BEGIN_PRIVATE_KEY"; then \ echo "$KASMVNC_ALPINE_PRIVATE_KEY" > $APK_KEYS_DIR/kasmvnc_signing_key.rsa; \ else \ @@ -20,10 +22,12 @@ RUN if echo "$KASMVNC_ALPINE_PRIVATE_KEY" | grep -q -- "$BEGIN_PRIVATE_KEY"; the $APK_KEYS_DIR/kasmvnc_signing_key.rsa; \ fi RUN echo KASMVNC_ALPINE_PRIVATE_KEY "$KASMVNC_ALPINE_PRIVATE_KEY" -RUN echo -n "$KASMVNC_ALPINE_PUBLIC_KEY" > \ - $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub -RUN echo KASMVNC_ALPINE_PUBLIC_KEY "$KASMVNC_ALPINE_PUBLIC_KEY" -RUN env +RUN if echo "$KASMVNC_ALPINE_PUBLIC_KEY" | grep -q -- "$BEGIN_PUBLIC_KEY"; then \ + echo "$KASMVNC_ALPINE_PUBLIC_KEY" > $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub; \ + else \ + echo -e "$BEGIN_PUBLIC_KEY\n$KASMVNC_ALPINE_PUBLIC_KEY\n$END_PUBLIC_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub; \ + fi RUN useradd -m docker && echo "docker:docker" | chpasswd From 72388b390b70ad6cd39f5afbf7a07ff708ee7616 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 16:24:08 +1300 Subject: [PATCH 040/167] KASM-6904 Fix CI --- builder/build-apk-inside-docker | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/builder/build-apk-inside-docker b/builder/build-apk-inside-docker index f06d9e8..e221814 100755 --- a/builder/build-apk-inside-docker +++ b/builder/build-apk-inside-docker @@ -8,6 +8,7 @@ apkbuild_dir=/src/alpine/kasmvncserver/ cd "$apkbuild_dir" && abuild -r -mkdir -p /src/builder/build/${os}_${os_codename} -mv \ +[ -n "$CI" ] && sudo_cmd=sudo || sudo_cmd= +$sudo_cmd mkdir -p /src/builder/build/${os}_${os_codename} +$sudo_cmd mv \ /src/alpine/packages/alpine/$(arch)/*.apk /src/builder/build/${os}_${os_codename}/ From 2eae9d294123b4640e2468db8e7a6c1cbb7f1167 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 16:31:45 +1300 Subject: [PATCH 041/167] KASM-6904 Debug CI --- builder/build-apk-inside-docker | 1 + 1 file changed, 1 insertion(+) diff --git a/builder/build-apk-inside-docker b/builder/build-apk-inside-docker index e221814..6c12dcb 100755 --- a/builder/build-apk-inside-docker +++ b/builder/build-apk-inside-docker @@ -8,6 +8,7 @@ apkbuild_dir=/src/alpine/kasmvncserver/ cd "$apkbuild_dir" && abuild -r +set -x [ -n "$CI" ] && sudo_cmd=sudo || sudo_cmd= $sudo_cmd mkdir -p /src/builder/build/${os}_${os_codename} $sudo_cmd mv \ From dfa1a00ed0bcc92a73e44725ff05953fe51fecbf Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 16:38:41 +1300 Subject: [PATCH 042/167] KASM-6904 Fix CI --- builder/build-apk | 1 + 1 file changed, 1 insertion(+) diff --git a/builder/build-apk b/builder/build-apk index 19f8f27..5b92170 100755 --- a/builder/build-apk +++ b/builder/build-apk @@ -33,5 +33,6 @@ copy_signing_key_to_user_abuild_dir source_dir=$(echo $PWD) docker run --rm -v "$source_dir":/src --user $L_UID:$L_GID \ --group-add $ABUILD_GID \ + -e CI \ kasmvnc_apkbuilder_${os}:${os_codename} /bin/bash -c \ '/src/builder/build-apk-inside-docker' From 896e66de3e8d6a5d67d73c87d8832cb8607a2028 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 17:15:00 +1300 Subject: [PATCH 043/167] KASM-6904 Fix CI --- builder/dockerfile.alpine_319.apk.build | 1 + 1 file changed, 1 insertion(+) diff --git a/builder/dockerfile.alpine_319.apk.build b/builder/dockerfile.alpine_319.apk.build index 2c60fef..c860e4b 100644 --- a/builder/dockerfile.alpine_319.apk.build +++ b/builder/dockerfile.alpine_319.apk.build @@ -30,5 +30,6 @@ RUN if echo "$KASMVNC_ALPINE_PUBLIC_KEY" | grep -q -- "$BEGIN_PUBLIC_KEY"; then fi RUN useradd -m docker && echo "docker:docker" | chpasswd +RUN echo 'docker ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers USER docker From fc79c216f50c82c31694df42da3049d1f87262ad Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 17:21:47 +1300 Subject: [PATCH 044/167] Revert "KASM-6904 Print env" This reverts commit be265fa9ee4396cd8ac25473341393b7eb3036ae. --- builder/build-apk | 2 -- 1 file changed, 2 deletions(-) diff --git a/builder/build-apk b/builder/build-apk index 5b92170..8b49160 100755 --- a/builder/build-apk +++ b/builder/build-apk @@ -21,8 +21,6 @@ if [ "$L_UID" = 0 ]; then L_GID=1000 fi -echo "woo" -env builder_image=kasmvnc_apkbuilder_${os}:${os_codename} docker build -t $builder_image \ --build-arg KASMVNC_ALPINE_PRIVATE_KEY \ From 1c279c2e941ecb7083159506c7d39d54263f545f Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 17:29:07 +1300 Subject: [PATCH 045/167] KASM-6904 Alpine: depend on xf86-video-intel only on x86 --- alpine/kasmvncserver/APKBUILD | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/alpine/kasmvncserver/APKBUILD b/alpine/kasmvncserver/APKBUILD index 3138c47..e67e4c2 100644 --- a/alpine/kasmvncserver/APKBUILD +++ b/alpine/kasmvncserver/APKBUILD @@ -36,11 +36,13 @@ depends=" xf86-video-amdgpu xf86-video-ati xf86-video-nouveau - xf86-video-intel xkbcomp xkeyboard-config xterm " +if [ $(arch) = x86_64 ]; then + depends="$depends xf86-video-intel" +fi makedepends=" rsync binutils From 5edf55ee9997c9cb2c8bbdcc30264d1dbbcdc9de Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 17:45:27 +1300 Subject: [PATCH 046/167] KASM-6904 Refactor --- builder/dockerfile.alpine_319.apk.build | 21 +++------------ builder/scripts/install_alpine_signing_keys | 29 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 17 deletions(-) create mode 100755 builder/scripts/install_alpine_signing_keys diff --git a/builder/dockerfile.alpine_319.apk.build b/builder/dockerfile.alpine_319.apk.build index c860e4b..35e0dc7 100644 --- a/builder/dockerfile.alpine_319.apk.build +++ b/builder/dockerfile.alpine_319.apk.build @@ -11,23 +11,10 @@ WORKDIR $HOME/kasmvncserver ARG KASMVNC_ALPINE_PRIVATE_KEY ARG KASMVNC_ALPINE_PUBLIC_KEY ENV APK_KEYS_DIR=/etc/apk/keys -ENV BEGIN_PRIVATE_KEY='-----BEGIN PRIVATE KEY-----' -ENV END_PRIVATE_KEY='-----END PRIVATE KEY-----' -ENV BEGIN_PUBLIC_KEY='-----BEGIN PUBLIC KEY-----' -ENV END_PUBLIC_KEY='-----END PUBLIC KEY-----' -RUN if echo "$KASMVNC_ALPINE_PRIVATE_KEY" | grep -q -- "$BEGIN_PRIVATE_KEY"; then \ - echo "$KASMVNC_ALPINE_PRIVATE_KEY" > $APK_KEYS_DIR/kasmvnc_signing_key.rsa; \ - else \ - echo -e "$BEGIN_PRIVATE_KEY\n$KASMVNC_ALPINE_PRIVATE_KEY\n$END_PRIVATE_KEY" > \ - $APK_KEYS_DIR/kasmvnc_signing_key.rsa; \ - fi -RUN echo KASMVNC_ALPINE_PRIVATE_KEY "$KASMVNC_ALPINE_PRIVATE_KEY" -RUN if echo "$KASMVNC_ALPINE_PUBLIC_KEY" | grep -q -- "$BEGIN_PUBLIC_KEY"; then \ - echo "$KASMVNC_ALPINE_PUBLIC_KEY" > $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub; \ - else \ - echo -e "$BEGIN_PUBLIC_KEY\n$KASMVNC_ALPINE_PUBLIC_KEY\n$END_PUBLIC_KEY" > \ - $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub; \ - fi + +ENV SCRIPTS_DIR=/tmp/scripts +COPY builder/scripts $SCRIPTS_DIR +RUN $SCRIPTS_DIR/install_alpine_signing_keys RUN useradd -m docker && echo "docker:docker" | chpasswd RUN echo 'docker ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers diff --git a/builder/scripts/install_alpine_signing_keys b/builder/scripts/install_alpine_signing_keys new file mode 100755 index 0000000..0fbe3da --- /dev/null +++ b/builder/scripts/install_alpine_signing_keys @@ -0,0 +1,29 @@ +#!/bin/bash + +set -e + +install_private_signing_key() { + if echo "$KASMVNC_ALPINE_PRIVATE_KEY" | grep -q -- "$BEGIN_PRIVATE_KEY"; then + echo "$KASMVNC_ALPINE_PRIVATE_KEY" > $APK_KEYS_DIR/kasmvnc_signing_key.rsa + else + echo -e "$BEGIN_PRIVATE_KEY\n$KASMVNC_ALPINE_PRIVATE_KEY\n$END_PRIVATE_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa + fi +} + +install_public_signing_key() { + if echo "$KASMVNC_ALPINE_PUBLIC_KEY" | grep -q -- "$BEGIN_PUBLIC_KEY"; then \ + echo "$KASMVNC_ALPINE_PUBLIC_KEY" > $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub + else + echo -e "$BEGIN_PUBLIC_KEY\n$KASMVNC_ALPINE_PUBLIC_KEY\n$END_PUBLIC_KEY" > \ + $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub + fi +} + +BEGIN_PRIVATE_KEY='-----BEGIN PRIVATE KEY-----' +END_PRIVATE_KEY='-----END PRIVATE KEY-----' +BEGIN_PUBLIC_KEY='-----BEGIN PUBLIC KEY-----' +END_PUBLIC_KEY='-----END PUBLIC KEY-----' + +install_private_signing_key +install_public_signing_key From c9ea601582e8d8375c804f2541ab192475735e76 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 17:51:37 +1300 Subject: [PATCH 047/167] KASM-6904 Refactor --- builder/dockerfile.alpine_319.apk.build | 1 - builder/scripts/install_alpine_signing_keys | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/dockerfile.alpine_319.apk.build b/builder/dockerfile.alpine_319.apk.build index 35e0dc7..ae0f4e8 100644 --- a/builder/dockerfile.alpine_319.apk.build +++ b/builder/dockerfile.alpine_319.apk.build @@ -10,7 +10,6 @@ WORKDIR $HOME/kasmvncserver ARG KASMVNC_ALPINE_PRIVATE_KEY ARG KASMVNC_ALPINE_PUBLIC_KEY -ENV APK_KEYS_DIR=/etc/apk/keys ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR diff --git a/builder/scripts/install_alpine_signing_keys b/builder/scripts/install_alpine_signing_keys index 0fbe3da..63c3630 100755 --- a/builder/scripts/install_alpine_signing_keys +++ b/builder/scripts/install_alpine_signing_keys @@ -20,6 +20,7 @@ install_public_signing_key() { fi } +APK_KEYS_DIR=/etc/apk/keys BEGIN_PRIVATE_KEY='-----BEGIN PRIVATE KEY-----' END_PRIVATE_KEY='-----END PRIVATE KEY-----' BEGIN_PUBLIC_KEY='-----BEGIN PUBLIC KEY-----' From 13d1656e2f91f302d0ab6dfa566b2a07c9e6c85f Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 17:52:52 +1300 Subject: [PATCH 048/167] KASM-6904 Refactor --- builder/dockerfile.alpine_319.apk.build | 2 -- 1 file changed, 2 deletions(-) diff --git a/builder/dockerfile.alpine_319.apk.build b/builder/dockerfile.alpine_319.apk.build index ae0f4e8..95b6bc6 100644 --- a/builder/dockerfile.alpine_319.apk.build +++ b/builder/dockerfile.alpine_319.apk.build @@ -3,8 +3,6 @@ FROM alpine:3.19 RUN apk add shadow bash RUN apk add abuild sudo less -SHELL ["/bin/bash", "-c"] - ENV HOME /src/alpine WORKDIR $HOME/kasmvncserver From ae1ec7e8d3d321b83e0e887059faaefa99044257 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 17:54:44 +1300 Subject: [PATCH 049/167] Revert "KASM-6904 CI: .abuild as artifacts" This reverts commit 90351722729fcd783b79abdf45ca9a315dd9facf. --- .gitlab-ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a9fbc7c..308e3c8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -779,8 +779,6 @@ build_alpine_319: artifacts: paths: - output/ - - alpine/.abuild - when: always build_alpine_319_arm: stage: build From cfa0fd11e756590cc4c3d17baa53ff042ceb6534 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 17:56:42 +1300 Subject: [PATCH 050/167] KASM-6904 Alpine 3.18 build apk package --- .gitlab-ci.yml | 2 +- builder/dockerfile.alpine_318.apk.build | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 308e3c8..6ab8318 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ variables: # E.g. BUILD_JOBS: build_debian_buster,build_ubuntu_bionic. This will include # arm builds, because build_debian_buster_arm matches build_debian_buster. # "BUILD_JOBS: none" won't build any build jobs, nor www. - BUILD_JOBS: build_alpine_319 + BUILD_JOBS: build_alpine_318 DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" diff --git a/builder/dockerfile.alpine_318.apk.build b/builder/dockerfile.alpine_318.apk.build index 209e142..f55ac41 100644 --- a/builder/dockerfile.alpine_318.apk.build +++ b/builder/dockerfile.alpine_318.apk.build @@ -8,12 +8,12 @@ WORKDIR $HOME/kasmvncserver ARG KASMVNC_ALPINE_PRIVATE_KEY ARG KASMVNC_ALPINE_PUBLIC_KEY -ENV APK_KEYS_DIR=/etc/apk/keys -RUN echo -n "$KASMVNC_ALPINE_PRIVATE_KEY" > \ - $APK_KEYS_DIR/kasmvnc_signing_key.rsa -RUN echo -n "$KASMVNC_ALPINE_PUBLIC_KEY" > \ - $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub + +ENV SCRIPTS_DIR=/tmp/scripts +COPY builder/scripts $SCRIPTS_DIR +RUN $SCRIPTS_DIR/install_alpine_signing_keys RUN useradd -m docker && echo "docker:docker" | chpasswd +RUN echo 'docker ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers USER docker From e6a805d6e14d74c34b88c5a654963a62c5e9243a Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 17:57:35 +1300 Subject: [PATCH 051/167] KASM-6904 Remove debug code --- builder/build-apk-inside-docker | 1 - 1 file changed, 1 deletion(-) diff --git a/builder/build-apk-inside-docker b/builder/build-apk-inside-docker index 6c12dcb..e221814 100755 --- a/builder/build-apk-inside-docker +++ b/builder/build-apk-inside-docker @@ -8,7 +8,6 @@ apkbuild_dir=/src/alpine/kasmvncserver/ cd "$apkbuild_dir" && abuild -r -set -x [ -n "$CI" ] && sudo_cmd=sudo || sudo_cmd= $sudo_cmd mkdir -p /src/builder/build/${os}_${os_codename} $sudo_cmd mv \ From 7726718e1ae970f6b8c185dacdc9ff581933609d Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 18:24:59 +1300 Subject: [PATCH 052/167] KASM-6904 Alpine 3.17 build apk package --- .gitlab-ci.yml | 2 +- builder/dockerfile.alpine_317.apk.build | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6ab8318..4f28162 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ variables: # E.g. BUILD_JOBS: build_debian_buster,build_ubuntu_bionic. This will include # arm builds, because build_debian_buster_arm matches build_debian_buster. # "BUILD_JOBS: none" won't build any build jobs, nor www. - BUILD_JOBS: build_alpine_318 + BUILD_JOBS: build_alpine_317 DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" diff --git a/builder/dockerfile.alpine_317.apk.build b/builder/dockerfile.alpine_317.apk.build index fafdecb..c0294c0 100644 --- a/builder/dockerfile.alpine_317.apk.build +++ b/builder/dockerfile.alpine_317.apk.build @@ -8,12 +8,12 @@ WORKDIR $HOME/kasmvncserver ARG KASMVNC_ALPINE_PRIVATE_KEY ARG KASMVNC_ALPINE_PUBLIC_KEY -ENV APK_KEYS_DIR=/etc/apk/keys -RUN echo -n "$KASMVNC_ALPINE_PRIVATE_KEY" > \ - $APK_KEYS_DIR/kasmvnc_signing_key.rsa -RUN echo -n "$KASMVNC_ALPINE_PUBLIC_KEY" > \ - $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub + +ENV SCRIPTS_DIR=/tmp/scripts +COPY builder/scripts $SCRIPTS_DIR +RUN $SCRIPTS_DIR/install_alpine_signing_keys RUN useradd -m docker && echo "docker:docker" | chpasswd +RUN echo 'docker ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers USER docker From d607c2e7f78babcc31ecd35a5bd0b4857f4601c1 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 18:29:57 +1300 Subject: [PATCH 053/167] KASM-6904 Alpine 3.20 build apk package --- .gitlab-ci.yml | 2 +- builder/dockerfile.alpine_320.apk.build | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4f28162..2fd3f69 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ variables: # E.g. BUILD_JOBS: build_debian_buster,build_ubuntu_bionic. This will include # arm builds, because build_debian_buster_arm matches build_debian_buster. # "BUILD_JOBS: none" won't build any build jobs, nor www. - BUILD_JOBS: build_alpine_317 + BUILD_JOBS: build_alpine_320 DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" diff --git a/builder/dockerfile.alpine_320.apk.build b/builder/dockerfile.alpine_320.apk.build index 515d825..8791c8b 100644 --- a/builder/dockerfile.alpine_320.apk.build +++ b/builder/dockerfile.alpine_320.apk.build @@ -8,12 +8,12 @@ WORKDIR $HOME/kasmvncserver ARG KASMVNC_ALPINE_PRIVATE_KEY ARG KASMVNC_ALPINE_PUBLIC_KEY -ENV APK_KEYS_DIR=/etc/apk/keys -RUN echo -n "$KASMVNC_ALPINE_PRIVATE_KEY" > \ - $APK_KEYS_DIR/kasmvnc_signing_key.rsa -RUN echo -n "$KASMVNC_ALPINE_PUBLIC_KEY" > \ - $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub + +ENV SCRIPTS_DIR=/tmp/scripts +COPY builder/scripts $SCRIPTS_DIR +RUN $SCRIPTS_DIR/install_alpine_signing_keys RUN useradd -m docker && echo "docker:docker" | chpasswd +RUN echo 'docker ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers USER docker From 15ee0f3dbeebc36dc075f2a9060de0cf676b50c5 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 18:31:36 +1300 Subject: [PATCH 054/167] KASM-6904 Alpine 3.21 build apk package --- .gitlab-ci.yml | 2 +- builder/dockerfile.alpine_321.apk.build | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2fd3f69..564640b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ variables: # E.g. BUILD_JOBS: build_debian_buster,build_ubuntu_bionic. This will include # arm builds, because build_debian_buster_arm matches build_debian_buster. # "BUILD_JOBS: none" won't build any build jobs, nor www. - BUILD_JOBS: build_alpine_320 + BUILD_JOBS: build_alpine_321 DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" diff --git a/builder/dockerfile.alpine_321.apk.build b/builder/dockerfile.alpine_321.apk.build index 8771f31..2bc1af0 100644 --- a/builder/dockerfile.alpine_321.apk.build +++ b/builder/dockerfile.alpine_321.apk.build @@ -8,12 +8,12 @@ WORKDIR $HOME/kasmvncserver ARG KASMVNC_ALPINE_PRIVATE_KEY ARG KASMVNC_ALPINE_PUBLIC_KEY -ENV APK_KEYS_DIR=/etc/apk/keys -RUN echo -n "$KASMVNC_ALPINE_PRIVATE_KEY" > \ - $APK_KEYS_DIR/kasmvnc_signing_key.rsa -RUN echo -n "$KASMVNC_ALPINE_PUBLIC_KEY" > \ - $APK_KEYS_DIR/kasmvnc_signing_key.rsa.pub + +ENV SCRIPTS_DIR=/tmp/scripts +COPY builder/scripts $SCRIPTS_DIR +RUN $SCRIPTS_DIR/install_alpine_signing_keys RUN useradd -m docker && echo "docker:docker" | chpasswd +RUN echo 'docker ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers USER docker From 8dc2dca965c8700010b3eb2ebcf1c968facff433 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 18:32:48 +1300 Subject: [PATCH 055/167] KASM-6904 CI: build for all distros --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 564640b..3279217 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ variables: # E.g. BUILD_JOBS: build_debian_buster,build_ubuntu_bionic. This will include # arm builds, because build_debian_buster_arm matches build_debian_buster. # "BUILD_JOBS: none" won't build any build jobs, nor www. - BUILD_JOBS: build_alpine_321 + BUILD_JOBS: all DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" From 471a6813e4704ce4580f43e081d32d7a0abd61f0 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sun, 9 Mar 2025 19:38:01 +1300 Subject: [PATCH 056/167] KASM-6904 Alpine dev env: add apk-del-add command --- alpine/apk-del-add | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100755 alpine/apk-del-add diff --git a/alpine/apk-del-add b/alpine/apk-del-add new file mode 100755 index 0000000..f4840cd --- /dev/null +++ b/alpine/apk-del-add @@ -0,0 +1,8 @@ +#!/bin/sh + +set -e + +sudo apk del kasmvncserver || true +rm -r ../packages +abuild -r || true +sudo apk add ../packages/src/x86_64/kasmvncserver-1.3.3-r0.apk --allow-untrusted From 5eb189d8ae1e041c1cbc536f7ce72e76c4ca7094 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Mon, 10 Mar 2025 15:42:09 +1300 Subject: [PATCH 057/167] KASM-6904 Alpine: depend on libxtst --- alpine/kasmvncserver/APKBUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/alpine/kasmvncserver/APKBUILD b/alpine/kasmvncserver/APKBUILD index e67e4c2..0030b35 100644 --- a/alpine/kasmvncserver/APKBUILD +++ b/alpine/kasmvncserver/APKBUILD @@ -16,6 +16,7 @@ depends=" libwebp libxfont2 libxshmfence + libxtst mcookie mesa-gbm openssl From d932af7456132ada759db57dbaab48bcc594a6bf Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Mon, 10 Mar 2025 15:43:35 +1300 Subject: [PATCH 058/167] KASM-6904 Build only Alpine 3.21 arm --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3279217..d13eabc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ variables: # E.g. BUILD_JOBS: build_debian_buster,build_ubuntu_bionic. This will include # arm builds, because build_debian_buster_arm matches build_debian_buster. # "BUILD_JOBS: none" won't build any build jobs, nor www. - BUILD_JOBS: all + BUILD_JOBS: build_alpine_321_arm DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" From abf4cb846c8abfd99a3eb34d6070d3bcb6f63440 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Mon, 10 Mar 2025 15:51:00 +1300 Subject: [PATCH 059/167] Revert "KASM-6904 Build only Alpine 3.21 arm" This reverts commit d932af7456132ada759db57dbaab48bcc594a6bf. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d13eabc..3279217 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ variables: # E.g. BUILD_JOBS: build_debian_buster,build_ubuntu_bionic. This will include # arm builds, because build_debian_buster_arm matches build_debian_buster. # "BUILD_JOBS: none" won't build any build jobs, nor www. - BUILD_JOBS: build_alpine_321_arm + BUILD_JOBS: all DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" From bfbb4fb88ffaab8d4874f5fc1f2cf354c93c70fc Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Mon, 10 Mar 2025 16:53:34 +1300 Subject: [PATCH 060/167] KASM-6904 Git ignore Alpine artifacts --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index f4a278e..2fa2d43 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,7 @@ debian/kasmvncserver.substvars debian/kasmvncserver/ .pc .vscode/ + +alpine/.abuild/kasmvnc_signing_key.rsa +alpine/.abuild/kasmvnc_signing_key.rsa.pub +alpine/packages/ From fe28be2dc01db621be24258001fd8c39560ad933 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Mon, 10 Mar 2025 18:12:08 +1300 Subject: [PATCH 061/167] KASM-6904 Add arch to Alpine packages --- .ci/detect_os_arch_package_format | 2 ++ builder/build-apk-inside-docker | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/.ci/detect_os_arch_package_format b/.ci/detect_os_arch_package_format index dc76376..adf4a56 100755 --- a/.ci/detect_os_arch_package_format +++ b/.ci/detect_os_arch_package_format @@ -4,8 +4,10 @@ package_name = ARGV.first DEB_PACKAGE_REGEX = %r!(?[^/]+)/kasmvncserver_.+?_(?.+?).(?deb)! RPM_PACKAGE_REGEX = %r!(?[^/]+)/kasmvncserver-.+?\.(?[^.]+).(?rpm)! +ALPINE_PACKAGE_REGEX = %r!(?[^/]+)/kasmvncserver-.+?-r\d+_(?[^.]+)\.(?apk)! if matches = package_name.match(DEB_PACKAGE_REGEX) +elsif matches = package_name.match(ALPINE_PACKAGE_REGEX) else matches = package_name.match(RPM_PACKAGE_REGEX) end diff --git a/builder/build-apk-inside-docker b/builder/build-apk-inside-docker index e221814..75322e3 100755 --- a/builder/build-apk-inside-docker +++ b/builder/build-apk-inside-docker @@ -2,6 +2,12 @@ set -e +add_arch_to_apk_package() { + package_name=$(ls *.apk | grep -v kasmvncserver-doc) + new_package_name=$(echo "$package_name" | sed -e 's/\(-r[[:digit:]]\+\)/\1_'$(arch)/) + $sudo_cmd mv "$package_name" "$new_package_name" +} + os=alpine os_codename=$(cat /etc/os-release | awk '/VERSION_ID/' | grep -o '[[:digit:]]' | tr -d '\n' | head -c 3) apkbuild_dir=/src/alpine/kasmvncserver/ @@ -10,5 +16,6 @@ cd "$apkbuild_dir" && abuild -r [ -n "$CI" ] && sudo_cmd=sudo || sudo_cmd= $sudo_cmd mkdir -p /src/builder/build/${os}_${os_codename} +( cd /src/alpine/packages/alpine/$(arch)/ && add_arch_to_apk_package ) $sudo_cmd mv \ /src/alpine/packages/alpine/$(arch)/*.apk /src/builder/build/${os}_${os_codename}/ From 1cb0a6a3b95402ea087f1732ba494492236c6382 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Wed, 12 Mar 2025 16:05:44 +1300 Subject: [PATCH 062/167] KASM-6904 CI: upload apk --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3279217..bb63d3b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -900,7 +900,7 @@ upload: - export S3_BUILD_DIRECTORY="kasmvnc/${CI_COMMIT_SHA}" - export RELEASE_VERSION=$(.ci/next_release_version "$CI_COMMIT_REF_NAME") - uploaded_files=() - - for package in `find output/ -type f -name '*.deb' -or -name '*.rpm' -or -name '*.tgz'`; do + - for package in `find output/ -type f -name '*.deb' -or -name '*.rpm' -or -name '*.apk'`; do prepare_upload_filename "$package"; upload_filename="${S3_BUILD_DIRECTORY}/$upload_filename"; echo; From 71e0409e644014f50064381243b8f3fd8dd8c6c8 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Wed, 12 Mar 2025 16:07:24 +1300 Subject: [PATCH 063/167] KASM-6904 Build only Alpine 3.21 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bb63d3b..58bc14c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ variables: # E.g. BUILD_JOBS: build_debian_buster,build_ubuntu_bionic. This will include # arm builds, because build_debian_buster_arm matches build_debian_buster. # "BUILD_JOBS: none" won't build any build jobs, nor www. - BUILD_JOBS: all + BUILD_JOBS: build_alpine_321 DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" From c6e84e4d8f8a603e0ce12fb4f026a28e6ef4f6d5 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Wed, 12 Mar 2025 16:17:59 +1300 Subject: [PATCH 064/167] KASM-6904 Debug CI --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 58bc14c..7784673 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -900,6 +900,7 @@ upload: - export S3_BUILD_DIRECTORY="kasmvnc/${CI_COMMIT_SHA}" - export RELEASE_VERSION=$(.ci/next_release_version "$CI_COMMIT_REF_NAME") - uploaded_files=() + - set -x; find output/ -type f -name '*.deb' -or -name '*.rpm' -or -name '*.apk'`; - for package in `find output/ -type f -name '*.deb' -or -name '*.rpm' -or -name '*.apk'`; do prepare_upload_filename "$package"; upload_filename="${S3_BUILD_DIRECTORY}/$upload_filename"; From 03239db5cff7badd8133bba7d3a198c874ee0d68 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Wed, 12 Mar 2025 16:29:00 +1300 Subject: [PATCH 065/167] KASM-6904 Debug CI --- .gitlab-ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7784673..8cd1e80 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,7 +22,7 @@ workflow: stages: - www - build - - test + # - test - upload .prepare_build: &prepare_build @@ -900,7 +900,6 @@ upload: - export S3_BUILD_DIRECTORY="kasmvnc/${CI_COMMIT_SHA}" - export RELEASE_VERSION=$(.ci/next_release_version "$CI_COMMIT_REF_NAME") - uploaded_files=() - - set -x; find output/ -type f -name '*.deb' -or -name '*.rpm' -or -name '*.apk'`; - for package in `find output/ -type f -name '*.deb' -or -name '*.rpm' -or -name '*.apk'`; do prepare_upload_filename "$package"; upload_filename="${S3_BUILD_DIRECTORY}/$upload_filename"; From 2912aa653ca867c7ecc6ec0fd31f805925b2192d Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Wed, 12 Mar 2025 16:29:46 +1300 Subject: [PATCH 066/167] KASM-6904 Debug CI --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8cd1e80..1020c2d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,7 +22,6 @@ workflow: stages: - www - build - # - test - upload .prepare_build: &prepare_build From 2bd7e9497a8ce0958cda683e22572ec96be1c315 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Wed, 12 Mar 2025 16:32:48 +1300 Subject: [PATCH 067/167] KASM-6904 Debug CI --- .gitlab-ci.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1020c2d..4bda2a7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,6 +22,7 @@ workflow: stages: - www - build +# - test - upload .prepare_build: &prepare_build @@ -712,14 +713,14 @@ build_alpine_317_arm: paths: - output/ -test: - stage: test - tags: - - oci-fixed-amd - before_script: - - *prepare_build - script: - - bash builder/test-vncserver +# test: +# stage: test +# tags: +# - oci-fixed-amd +# before_script: +# - *prepare_build +# script: +# - bash builder/test-vncserver build_alpine_318: From 47b95c4659170b14c9ee120d42031ab9646b3a97 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Thu, 13 Mar 2025 16:18:39 +1300 Subject: [PATCH 068/167] KASM-6904 Restore CI test stage --- .gitlab-ci.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4bda2a7..bb63d3b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ variables: # E.g. BUILD_JOBS: build_debian_buster,build_ubuntu_bionic. This will include # arm builds, because build_debian_buster_arm matches build_debian_buster. # "BUILD_JOBS: none" won't build any build jobs, nor www. - BUILD_JOBS: build_alpine_321 + BUILD_JOBS: all DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" @@ -22,7 +22,7 @@ workflow: stages: - www - build -# - test + - test - upload .prepare_build: &prepare_build @@ -713,14 +713,14 @@ build_alpine_317_arm: paths: - output/ -# test: -# stage: test -# tags: -# - oci-fixed-amd -# before_script: -# - *prepare_build -# script: -# - bash builder/test-vncserver +test: + stage: test + tags: + - oci-fixed-amd + before_script: + - *prepare_build + script: + - bash builder/test-vncserver build_alpine_318: From 254f4d38f0ecb80889a4a43dcd820fdeab7b0f73 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Thu, 13 Mar 2025 17:19:38 +1300 Subject: [PATCH 069/167] KASM-6904 bump-package-version: support Alpine --- builder/bump-package-version | 6 ++++++ builder/bump-package-version-apk | 14 ++++++++++++++ 2 files changed, 20 insertions(+) create mode 100755 builder/bump-package-version-apk diff --git a/builder/bump-package-version b/builder/bump-package-version index 4e09e42..6f6824e 100755 --- a/builder/bump-package-version +++ b/builder/bump-package-version @@ -7,6 +7,11 @@ update_version_to_meet_packaging_standards() { sed -e 's/\([0-9]\)-\([a-zA-Z]\)/\1~\2/') } +bump_apk() { + builder/bump-package-version-apk "$new_version" +} + + bump_rpm() { builder/bump-package-version-rpm "$new_version" } @@ -33,3 +38,4 @@ update_version_to_meet_packaging_standards bump_xvnc_binary bump_rpm bump_deb +bump_apk diff --git a/builder/bump-package-version-apk b/builder/bump-package-version-apk new file mode 100755 index 0000000..60e778b --- /dev/null +++ b/builder/bump-package-version-apk @@ -0,0 +1,14 @@ +#!/bin/bash + +set -eo pipefail +set -x + +new_version="$1" +spec_file=alpine/kasmvncserver/APKBUILD + +bump_version() { + sed -i "s/^pkgver=.\+/pkgver=$new_version/" "$1" + sed -i "s/^pkgrel=.\+/pkgver=0/" "$1" +} + +bump_version $spec_file From 7f52b7ffc2d27b98ef978ac09972bfce39445a7d Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Thu, 13 Mar 2025 20:19:55 +1300 Subject: [PATCH 070/167] KASM-6904 Alpine: use common naming for kasmvncserver-doc package --- .ci/detect_os_arch_package_format | 2 +- .ci/upload.sh | 2 +- builder/build-apk-inside-docker | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.ci/detect_os_arch_package_format b/.ci/detect_os_arch_package_format index adf4a56..6b12647 100755 --- a/.ci/detect_os_arch_package_format +++ b/.ci/detect_os_arch_package_format @@ -4,7 +4,7 @@ package_name = ARGV.first DEB_PACKAGE_REGEX = %r!(?[^/]+)/kasmvncserver_.+?_(?.+?).(?deb)! RPM_PACKAGE_REGEX = %r!(?[^/]+)/kasmvncserver-.+?\.(?[^.]+).(?rpm)! -ALPINE_PACKAGE_REGEX = %r!(?[^/]+)/kasmvncserver-.+?-r\d+_(?[^.]+)\.(?apk)! +ALPINE_PACKAGE_REGEX = %r!(?[^/]+)/kasmvncserver-(doc-)?.+?-r\d+_(?[^.]+)\.(?apk)! if matches = package_name.match(DEB_PACKAGE_REGEX) elsif matches = package_name.match(ALPINE_PACKAGE_REGEX) diff --git a/.ci/upload.sh b/.ci/upload.sh index fc6aeb1..9200c8e 100644 --- a/.ci/upload.sh +++ b/.ci/upload.sh @@ -3,7 +3,7 @@ is_kasmvnc() { local package="$1"; - echo "$package" | grep -qP 'kasmvncserver(_|-)[0-9]' + echo "$package" | grep -qP 'kasmvncserver(_|-)(doc-)?[0-9]' } detect_deb_package_arch() { diff --git a/builder/build-apk-inside-docker b/builder/build-apk-inside-docker index 75322e3..4d7841b 100755 --- a/builder/build-apk-inside-docker +++ b/builder/build-apk-inside-docker @@ -3,11 +3,18 @@ set -e add_arch_to_apk_package() { - package_name=$(ls *.apk | grep -v kasmvncserver-doc) + local package_name="$1" + new_package_name=$(echo "$package_name" | sed -e 's/\(-r[[:digit:]]\+\)/\1_'$(arch)/) $sudo_cmd mv "$package_name" "$new_package_name" } +add_arch_to_apk_packages() { + for package_name in $(ls *.apk); do + add_arch_to_apk_package "$package_name" + done +} + os=alpine os_codename=$(cat /etc/os-release | awk '/VERSION_ID/' | grep -o '[[:digit:]]' | tr -d '\n' | head -c 3) apkbuild_dir=/src/alpine/kasmvncserver/ @@ -16,6 +23,6 @@ cd "$apkbuild_dir" && abuild -r [ -n "$CI" ] && sudo_cmd=sudo || sudo_cmd= $sudo_cmd mkdir -p /src/builder/build/${os}_${os_codename} -( cd /src/alpine/packages/alpine/$(arch)/ && add_arch_to_apk_package ) +( cd /src/alpine/packages/alpine/$(arch)/ && add_arch_to_apk_packages ) $sudo_cmd mv \ /src/alpine/packages/alpine/$(arch)/*.apk /src/builder/build/${os}_${os_codename}/ From ebe5855d6df981652e29f6dc74f1a860809f9cb8 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 14 Mar 2025 15:23:30 +1300 Subject: [PATCH 071/167] KASM-6901 Alpine: upload doc package --- .ci/upload.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.ci/upload.sh b/.ci/upload.sh index 9200c8e..cc51e50 100644 --- a/.ci/upload.sh +++ b/.ci/upload.sh @@ -27,6 +27,13 @@ fetch_xvnc_md5sum() { cat DEBIAN/md5sums | grep bin/Xkasmvnc | cut -d' ' -f 1 } +detect_alpine_doc_package() { + is_alpine_doc_package= + if [[ $package =~ kasmvncserver-doc ]]; then + is_alpine_doc_package=1 + fi +} + function prepare_upload_filename() { local package="$1"; @@ -44,11 +51,13 @@ function prepare_upload_filename() { REVISION="_${REVISION}" fi + detect_alpine_doc_package + if [ -n "$RELEASE_BRANCH" ]; then - export upload_filename="kasmvncserver_${PACKAGE_OS}_${RELEASE_VERSION}${REVISION}_${OS_ARCH}.${PACKAGE_FORMAT}"; + export upload_filename="kasmvncserver${is_alpine_doc_package:+_doc}_${PACKAGE_OS}_${RELEASE_VERSION}${REVISION}_${OS_ARCH}.${PACKAGE_FORMAT}"; else export SANITIZED_BRANCH="$(echo $CI_COMMIT_REF_NAME | sed 's/\//_/g')"; - export upload_filename="kasmvncserver_${PACKAGE_OS}_${RELEASE_VERSION}_${SANITIZED_BRANCH}_${CI_COMMIT_SHA:0:6}${REVISION}_${OS_ARCH}.${PACKAGE_FORMAT}"; + export upload_filename="kasmvncserver${is_alpine_doc_package:+_doc}_${PACKAGE_OS}_${RELEASE_VERSION}_${SANITIZED_BRANCH}_${CI_COMMIT_SHA:0:6}${REVISION}_${OS_ARCH}.${PACKAGE_FORMAT}"; fi }; From 035709529668bb27607f20fab473b1010aad92d6 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 14 Mar 2025 16:22:19 +1300 Subject: [PATCH 072/167] KASM-6904 Refactor --- alpine/kasmvncserver/APKBUILD | 37 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/alpine/kasmvncserver/APKBUILD b/alpine/kasmvncserver/APKBUILD index 0030b35..b98d00b 100644 --- a/alpine/kasmvncserver/APKBUILD +++ b/alpine/kasmvncserver/APKBUILD @@ -73,30 +73,29 @@ package() { export SRC="$srcdir/usr/local"; export SRC_BIN="$SRC/bin"; export DESTDIR="$pkgdir"; - export DST_MAN="$DESTDIR/usr/share/man/man1"; echo "installing files"; - mkdir -p $pkgdir/usr/bin $pkgdir/usr/lib \ - $pkgdir/usr/share/perl5/vendor_perl $pkgdir/etc/kasmvnc; - cp $SRC_BIN/Xvnc $pkgdir/usr/bin/Xkasmvnc; - cd $pkgdir/usr/bin/ && ln -s Xkasmvnc Xvnc; - cp $SRC_BIN/vncserver $pkgdir/usr/bin/kasmvncserver; - cd $pkgdir/usr/bin/ && ln -s kasmvncserver vncserver; - cp -r $SRC_BIN/KasmVNC $pkgdir/usr/share/perl5/vendor_perl; - cp $SRC_BIN/vncconfig $pkgdir/usr/bin/kasmvncconfig; - cp $SRC_BIN/kasmvncpasswd $pkgdir/usr/bin/; - cd $pkgdir/usr/bin/ && ln -s kasmvncpasswd vncpasswd; - cp $SRC_BIN/kasmxproxy $pkgdir/usr/bin/; - cp -r $SRC/lib/kasmvnc/ $pkgdir/usr/lib/kasmvncserver; + mkdir -p $DESTDIR/usr/bin $DESTDIR/usr/lib \ + $DESTDIR/usr/share/perl5/vendor_perl $DESTDIR/etc/kasmvnc; + cp $SRC_BIN/Xvnc $DESTDIR/usr/bin/Xkasmvnc; + cd $DESTDIR/usr/bin/ && ln -s Xkasmvnc Xvnc; + cp $SRC_BIN/vncserver $DESTDIR/usr/bin/kasmvncserver; + cd $DESTDIR/usr/bin/ && ln -s kasmvncserver vncserver; + cp -r $SRC_BIN/KasmVNC $DESTDIR/usr/share/perl5/vendor_perl; + cp $SRC_BIN/vncconfig $DESTDIR/usr/bin/kasmvncconfig; + cp $SRC_BIN/kasmvncpasswd $DESTDIR/usr/bin/; + cd $DESTDIR/usr/bin/ && ln -s kasmvncpasswd vncpasswd; + cp $SRC_BIN/kasmxproxy $DESTDIR/usr/bin/; + cp -r $SRC/lib/kasmvnc/ $DESTDIR/usr/lib/kasmvncserver; rsync -r --links --safe-links --exclude '.git*' --exclude po2js \ --exclude xgettext-html --exclude www/utils/ --exclude .eslintrc \ - $SRC/share/kasmvnc $pkgdir/usr/share; + $SRC/share/kasmvnc $DESTDIR/usr/share; sed -i -e 's!pem_certificate: .\+$!pem_certificate: /etc/ssl/private/kasmvnc.pem!' \ $DESTDIR/usr/share/kasmvnc/kasmvnc_defaults.yaml sed -i -e 's!pem_key: .\+$!pem_key: /etc/ssl/private/kasmvnc.pem!' \ $DESTDIR/usr/share/kasmvnc/kasmvnc_defaults.yaml sed -e 's/^\([^#]\)/# \1/' $SRC/share/kasmvnc/kasmvnc_defaults.yaml > \ - $pkgdir/etc/kasmvnc/kasmvnc.yaml; + $DESTDIR/etc/kasmvnc/kasmvnc.yaml; } doc() { @@ -106,10 +105,10 @@ doc() { export DESTDIR="$subpkgdir"; export DST_MAN="$DESTDIR/usr/share/man/man1"; - mkdir -p $subpkgdir/usr/share/man/man1 \ - $subpkgdir/usr/share/doc/kasmvncserver - cp -r $SRC/share/doc/kasmvnc*/* $subpkgdir/usr/share/doc/kasmvncserver/ - cp $SRC/man/man1/Xvnc.1 $subpkgdir/usr/share/man/man1/Xkasmvnc.1 + mkdir -p $DESTDIR/usr/share/man/man1 \ + $DESTDIR/usr/share/doc/kasmvncserver + cp -r $SRC/share/doc/kasmvnc*/* $DESTDIR/usr/share/doc/kasmvncserver/ + cp $SRC/man/man1/Xvnc.1 $DESTDIR/usr/share/man/man1/Xkasmvnc.1 cp $SRC/share/man/man1/vncserver.1 $DST_MAN/kasmvncserver.1 cp $SRC/share/man/man1/kasmxproxy.1 $DST_MAN/kasmxproxy.1 cp $SRC/share/man/man1/vncpasswd.1 $DST_MAN/kasmvncpasswd.1 From d9131dc9886f0013987cdc711857f77cf012898f Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Fri, 14 Mar 2025 16:27:22 +1300 Subject: [PATCH 073/167] KASM-6904 bump-package-version-apk: disable debug output --- builder/bump-package-version-apk | 1 - 1 file changed, 1 deletion(-) diff --git a/builder/bump-package-version-apk b/builder/bump-package-version-apk index 60e778b..adf77fe 100755 --- a/builder/bump-package-version-apk +++ b/builder/bump-package-version-apk @@ -1,7 +1,6 @@ #!/bin/bash set -eo pipefail -set -x new_version="$1" spec_file=alpine/kasmvncserver/APKBUILD From 462060189159c0056d98b9cc701e5126a154908e Mon Sep 17 00:00:00 2001 From: El Date: Mon, 17 Mar 2025 17:15:52 +0500 Subject: [PATCH 074/167] KASM-6773 Define WS_MAX_BUF_SIZE for buffer size standardization --- common/network/websocket.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/common/network/websocket.c b/common/network/websocket.c index f128ffe..bba66aa 100644 --- a/common/network/websocket.c +++ b/common/network/websocket.c @@ -70,6 +70,8 @@ void fatal(char *msg) exit(1); } +#define WS_MAX_BUF_SIZE 4096 + // 2022-05-18 19:51:26,810 [INFO] websocket 0: 71.62.44.0 172.12.15.5 - "GET /api/get_frame_stats?client=auto HTTP/1.1" 403 2 static void weblog(const unsigned code, const unsigned websocket, const uint8_t debug, @@ -834,7 +836,7 @@ static uint8_t isValidIp(const char *str, const unsigned len) { static void dirlisting(ws_ctx_t *ws_ctx, const char fullpath[], const char path[], const char * const user, const char * const ip, const char * const origip) { - char buf[4096]; + char buf[WS_MAX_BUF_SIZE]; char enc[PATH_MAX * 3 + 1]; unsigned i; @@ -895,7 +897,7 @@ static void dirlisting(ws_ctx_t *ws_ctx, const char fullpath[], const char path[ static void servefile(ws_ctx_t *ws_ctx, const char *in, const char * const user, const char * const ip, const char * const origip) { - char buf[4096], path[4096], fullpath[4096]; + char buf[WS_MAX_BUF_SIZE], path[PATH_MAX], fullpath[PATH_MAX]; //fprintf(stderr, "http servefile input '%s'\n", in); @@ -965,7 +967,7 @@ static void servefile(ws_ctx_t *ws_ctx, const char *in, const char * const user, //fprintf(stderr, "http servefile output '%s'\n", buf); unsigned count; - while ((count = fread(buf, 1, 4096, f))) { + while ((count = fread(buf, 1, WS_MAX_BUF_SIZE, f))) { ws_send(ws_ctx, buf, count); } fclose(f); @@ -1020,7 +1022,7 @@ notfound: } static void send403(ws_ctx_t *ws_ctx, const char * const origip, const char * const ip) { - char buf[4096]; + char buf[WS_MAX_BUF_SIZE]; sprintf(buf, "HTTP/1.1 403 Forbidden\r\n" "Server: KasmVNC/4.0\r\n" "Connection: close\r\n" @@ -1034,7 +1036,7 @@ static void send403(ws_ctx_t *ws_ctx, const char * const origip, const char * co static void send400(ws_ctx_t *ws_ctx, const char * const origip, const char * const ip, const char *info) { - char buf[4096]; + char buf[WS_MAX_BUF_SIZE]; sprintf(buf, "HTTP/1.1 400 Bad Request\r\n" "Server: KasmVNC/4.0\r\n" "Connection: close\r\n" @@ -1048,7 +1050,7 @@ static void send400(ws_ctx_t *ws_ctx, const char * const origip, const char * co static uint8_t ownerapi_post(ws_ctx_t *ws_ctx, const char *in, const char * const user, const char * const ip, const char * const origip) { - char buf[4096], path[4096]; + char buf[WS_MAX_BUF_SIZE], path[PATH_MAX]; uint8_t ret = 0; // 0 = continue checking in += 5; @@ -1237,7 +1239,7 @@ nope: static uint8_t ownerapi(ws_ctx_t *ws_ctx, const char *in, const char * const user, const char * const ip, const char * const origip) { - char buf[4096], path[4096], args[4096] = "", origpath[4096]; + char buf[WS_MAX_BUF_SIZE], path[PATH_MAX], args[PATH_MAX] = "", origpath[PATH_MAX]; uint8_t ret = 0; // 0 = continue checking if (strncmp(in, "GET ", 4)) { From 4e087ba790c239a0795cbac03f56e55812678e45 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 17 Mar 2025 17:17:03 +0500 Subject: [PATCH 075/167] KASM-6773 Refactor JSON_escape to use switch-case and handle NULL input --- common/network/jsonescape.c | 56 ++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/common/network/jsonescape.c b/common/network/jsonescape.c index 4bb0ef8..748e9e1 100644 --- a/common/network/jsonescape.c +++ b/common/network/jsonescape.c @@ -24,30 +24,40 @@ #include "cJSON.h" void JSON_escape(const char *in, char *out) { + if (!in) + return; + for (; *in; in++) { - if (in[0] == '\b') { - *out++ = '\\'; - *out++ = 'b'; - } else if (in[0] == '\f') { - *out++ = '\\'; - *out++ = 'f'; - } else if (in[0] == '\n') { - *out++ = '\\'; - *out++ = 'n'; - } else if (in[0] == '\r') { - *out++ = '\\'; - *out++ = 'r'; - } else if (in[0] == '\t') { - *out++ = '\\'; - *out++ = 't'; - } else if (in[0] == '"') { - *out++ = '\\'; - *out++ = '"'; - } else if (in[0] == '\\') { - *out++ = '\\'; - *out++ = '\\'; - } else { - *out++ = *in; + switch (*in) { + case '\b': + *out++ = '\\'; + *out++ = 'b'; + break; + case '\f': + *out++ = '\\'; + *out++ = 'f'; + case '\n': + *out++ = '\\'; + *out++ = 'n'; + break; + case '\r': + *out++ = '\\'; + *out++ = 'r'; + break; + case '\t': + *out++ = '\\'; + *out++ = 't'; + break; + case '"': + *out++ = '\\'; + *out++ = '"'; + break; + case '\\': + *out++ = '\\'; + *out++ = '\\'; + break; + default: + *out++ = *in; } } From 4973781a8f8926bd5b8102424529a59299494c4a Mon Sep 17 00:00:00 2001 From: El Date: Mon, 17 Mar 2025 17:19:57 +0500 Subject: [PATCH 076/167] KASM-6773 Use snprintf instead of sprintf for safer path handling --- common/network/websocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/network/websocket.c b/common/network/websocket.c index bba66aa..549181a 100644 --- a/common/network/websocket.c +++ b/common/network/websocket.c @@ -1689,7 +1689,7 @@ static uint8_t ownerapi(ws_ctx_t *ws_ctx, const char *in, const char * const use if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) continue; - sprintf(path, "%s/%s", allpath, ent->d_name); + snprintf(path, PATH_MAX, "%s/%s", allpath, ent->d_name); struct stat st; if (lstat(path, &st)) continue; From 0df5d5bd728953aa9e247ae324cd018b6d08a768 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 17 Mar 2025 17:20:26 +0500 Subject: [PATCH 077/167] KASM-6773 Escape JSON filenames in WebSocket file list responses --- common/network/websocket.c | 56 +++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/common/network/websocket.c b/common/network/websocket.c index 549181a..808d8d8 100644 --- a/common/network/websocket.c +++ b/common/network/websocket.c @@ -1673,11 +1673,11 @@ static uint8_t ownerapi(ws_ctx_t *ws_ctx, const char *in, const char * const use } sprintf(buf, "HTTP/1.1 200 OK\r\n" - "Server: KasmVNC/4.0\r\n" - "Connection: close\r\n" - "Content-type: text/json\r\n" - "%s" - "\r\n", extra_headers ? extra_headers : ""); + "Server: KasmVNC/4.0\r\n" + "Connection: close\r\n" + "Content-type: text/json\r\n" + "%s" + "\r\n", extra_headers ? extra_headers : ""); ws_send(ws_ctx, buf, strlen(buf)); len = 15; @@ -1711,23 +1711,35 @@ static uint8_t ownerapi(ws_ctx_t *ws_ctx, const char *in, const char * const use strcpy(grp, grpt.gr_name); } - sprintf(buf, "%s{ \"filename\": \"%s\", " - "\"date_modified\": %lu, " - "\"date_created\": %lu, " - "\"is_dir\": %s, " - "\"size\": %lu, " - "\"owner\": \"%s\", " - "\"group\": \"%s\", " - "\"perms\": \"%s\" }", - sent ? ",\n" : "", - ent->d_name, - st.st_mtime, - st.st_ctime, - S_ISDIR(st.st_mode) ? "true" : "false", - S_ISDIR(st.st_mode) ? 0 : st.st_size, - own, - grp, - perms); + sprintf(buf, "%s{ \"filename\": \"", sent ? ",\n" : ""); + ws_send(ws_ctx, buf, strlen(buf)); + len += strlen(buf); + + size_t max_out_length = 2 * strlen(ent->d_name) + 1; // worst case scenario + char *filename = malloc(max_out_length); + + JSON_escape(ent->d_name, filename); + size_t size = strlen(filename); + ws_send(ws_ctx, filename, size); + len += size; + + free(filename); + + sprintf(buf, "\", " + "\"date_modified\": %lu, " + "\"date_created\": %lu, " + "\"is_dir\": %s, " + "\"size\": %lu, " + "\"owner\": \"%s\", " + "\"group\": \"%s\", " + "\"perms\": \"%s\" }", + st.st_mtime, + st.st_ctime, + S_ISDIR(st.st_mode) ? "true" : "false", + S_ISDIR(st.st_mode) ? 0 : st.st_size, + own, + grp, + perms); sent = 1; ws_send(ws_ctx, buf, strlen(buf)); len += strlen(buf); From f2a19e6e091f9d1c0456806dfe79f5ab7f13219a Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Thu, 20 Mar 2025 16:24:07 +1300 Subject: [PATCH 078/167] KASM-7051 Set KasmVNC version to 1.3.4 --- alpine/kasmvncserver/APKBUILD | 4 ++-- debian/changelog | 6 ++++++ fedora/kasmvncserver.spec | 4 +++- opensuse/kasmvncserver.spec | 4 +++- oracle/kasmvncserver.spec | 4 +++- oracle/kasmvncserver9.spec | 4 +++- unix/xserver/hw/vnc/xvnc.c | 2 +- 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/alpine/kasmvncserver/APKBUILD b/alpine/kasmvncserver/APKBUILD index b98d00b..2e8ba2a 100644 --- a/alpine/kasmvncserver/APKBUILD +++ b/alpine/kasmvncserver/APKBUILD @@ -3,8 +3,8 @@ # Contributor: # Maintainer: Kasm Technologies LLC pkgname=kasmvncserver -pkgver=1.3.3 -pkgrel=0 +pkgver=1.3.4 +pkgver=0 pkgdesc="KasmVNC provides remote web-based access to a Desktop or application." url="https://github.com/kasmtech/KasmVNC" arch="x86_64 aarch64" diff --git a/debian/changelog b/debian/changelog index 4e2536b..4641ac3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +kasmvnc (1.3.4-1) unstable; urgency=medium + + * New upstream release. + + -- Kasm Technologies LLC Thu, 20 Mar 2025 03:21:46 +0000 + kasmvnc (1.3.3-1) unstable; urgency=medium * Allow disabling IP blacklist diff --git a/fedora/kasmvncserver.spec b/fedora/kasmvncserver.spec index 739530c..d7e45c5 100644 --- a/fedora/kasmvncserver.spec +++ b/fedora/kasmvncserver.spec @@ -1,5 +1,5 @@ Name: kasmvncserver -Version: 1.3.3 +Version: 1.3.4 Release: 1%{?dist} Summary: VNC server accessible from a web browser @@ -83,6 +83,8 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1; %doc /usr/share/doc/kasmvncserver/README.md %changelog +* Thu Mar 20 2025 KasmTech - 1.3.4-1 +- Upstream release * Fri Oct 25 2024 KasmTech - 1.3.3-1 - Allow disabling IP blacklist - Downloads API for detailed file downloads information diff --git a/opensuse/kasmvncserver.spec b/opensuse/kasmvncserver.spec index e7fdba1..9840e24 100644 --- a/opensuse/kasmvncserver.spec +++ b/opensuse/kasmvncserver.spec @@ -1,5 +1,5 @@ Name: kasmvncserver -Version: 1.3.3 +Version: 1.3.4 Release: leap15 Summary: VNC server accessible from a web browser @@ -81,6 +81,8 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1; %doc /usr/share/doc/kasmvncserver/README.md %changelog +* Thu Mar 20 2025 KasmTech - 1.3.4-leap15 +- Upstream release * Fri Oct 25 2024 KasmTech - 1.3.3-1 - Allow disabling IP blacklist - Downloads API for detailed file downloads information diff --git a/oracle/kasmvncserver.spec b/oracle/kasmvncserver.spec index 5edd055..15344ba 100644 --- a/oracle/kasmvncserver.spec +++ b/oracle/kasmvncserver.spec @@ -1,5 +1,5 @@ Name: kasmvncserver -Version: 1.3.3 +Version: 1.3.4 Release: 1%{?dist} Summary: VNC server accessible from a web browser @@ -82,6 +82,8 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1; %doc /usr/share/doc/kasmvncserver/README.md %changelog +* Thu Mar 20 2025 KasmTech - 1.3.4-1 +- Upstream release * Fri Oct 25 2024 KasmTech - 1.3.3-1 - Allow disabling IP blacklist - Downloads API for detailed file downloads information diff --git a/oracle/kasmvncserver9.spec b/oracle/kasmvncserver9.spec index 482587c..40dd966 100644 --- a/oracle/kasmvncserver9.spec +++ b/oracle/kasmvncserver9.spec @@ -1,5 +1,5 @@ Name: kasmvncserver -Version: 1.3.3 +Version: 1.3.4 Release: 1%{?dist} Summary: VNC server accessible from a web browser @@ -82,6 +82,8 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1; %doc /usr/share/doc/kasmvncserver/README.md %changelog +* Thu Mar 20 2025 KasmTech - 1.3.4-1 +- Upstream release * Fri Oct 25 2024 KasmTech - 1.3.3-1 - Allow disabling IP blacklist - Downloads API for detailed file downloads information diff --git a/unix/xserver/hw/vnc/xvnc.c b/unix/xserver/hw/vnc/xvnc.c index cc500f4..7c196dc 100644 --- a/unix/xserver/hw/vnc/xvnc.c +++ b/unix/xserver/hw/vnc/xvnc.c @@ -95,7 +95,7 @@ from the X Consortium. #undef VENDOR_STRING #include "version-config.h" -#define XVNCVERSION "KasmVNC 1.3.3" +#define XVNCVERSION "KasmVNC 1.3.4" #define XVNCCOPYRIGHT ("Copyright (C) 1999-2018 KasmVNC Team and many others (see README.me)\n" \ "See http://kasmweb.com for information on KasmVNC.\n") From 16d02f6c2f9f6327d491e33a05a9c6a85f7ea6bf Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Thu, 20 Mar 2025 17:21:44 +1300 Subject: [PATCH 079/167] KASM-7051 Fix APKBUILD by adding pkgrel --- alpine/kasmvncserver/APKBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alpine/kasmvncserver/APKBUILD b/alpine/kasmvncserver/APKBUILD index 2e8ba2a..f5fb900 100644 --- a/alpine/kasmvncserver/APKBUILD +++ b/alpine/kasmvncserver/APKBUILD @@ -4,7 +4,7 @@ # Maintainer: Kasm Technologies LLC pkgname=kasmvncserver pkgver=1.3.4 -pkgver=0 +pkgrel=0 pkgdesc="KasmVNC provides remote web-based access to a Desktop or application." url="https://github.com/kasmtech/KasmVNC" arch="x86_64 aarch64" From 297554dd671e5eedbea45af69a691a11ce9d7200 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Thu, 20 Mar 2025 17:23:11 +1300 Subject: [PATCH 080/167] KASM-7051 bump-package-version-apk: fix to produce pkgrel --- builder/bump-package-version-apk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/bump-package-version-apk b/builder/bump-package-version-apk index adf77fe..359fcd3 100755 --- a/builder/bump-package-version-apk +++ b/builder/bump-package-version-apk @@ -7,7 +7,7 @@ spec_file=alpine/kasmvncserver/APKBUILD bump_version() { sed -i "s/^pkgver=.\+/pkgver=$new_version/" "$1" - sed -i "s/^pkgrel=.\+/pkgver=0/" "$1" + sed -i "s/^pkgrel=.\+/pkgrel=0/" "$1" } bump_version $spec_file From 2e0da8f034c595cedc20e2fb0afddb8e84ebf939 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Mon, 24 Mar 2025 17:11:51 +1300 Subject: [PATCH 081/167] KASM-7051 Fill release notes for deb and rpm --- debian/changelog | 5 ++++- fedora/kasmvncserver.spec | 5 ++++- opensuse/kasmvncserver.spec | 5 ++++- oracle/kasmvncserver.spec | 5 ++++- oracle/kasmvncserver9.spec | 5 ++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/debian/changelog b/debian/changelog index 4641ac3..19f0a73 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,9 @@ kasmvnc (1.3.4-1) unstable; urgency=medium - * New upstream release. + * Add configuration key network.udp.payload_size. + * Remove support for distro versions that reached end-of-life. + * Add missing dependency on libdatetime-perl. + * Remove webpack to reduce security vulnerabilities. -- Kasm Technologies LLC Thu, 20 Mar 2025 03:21:46 +0000 diff --git a/fedora/kasmvncserver.spec b/fedora/kasmvncserver.spec index d7e45c5..f3873fb 100644 --- a/fedora/kasmvncserver.spec +++ b/fedora/kasmvncserver.spec @@ -84,7 +84,10 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1; %changelog * Thu Mar 20 2025 KasmTech - 1.3.4-1 -- Upstream release +- Add configuration key network.udp.payload_size. +- Remove support for distro versions that reached end-of-life. +- Add missing dependency on hostname. +- Remove webpack to reduce security vulnerabilities. * Fri Oct 25 2024 KasmTech - 1.3.3-1 - Allow disabling IP blacklist - Downloads API for detailed file downloads information diff --git a/opensuse/kasmvncserver.spec b/opensuse/kasmvncserver.spec index 9840e24..cad1809 100644 --- a/opensuse/kasmvncserver.spec +++ b/opensuse/kasmvncserver.spec @@ -82,7 +82,10 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1; %changelog * Thu Mar 20 2025 KasmTech - 1.3.4-leap15 -- Upstream release +- Add configuration key network.udp.payload_size. +- Remove support for distro versions that reached end-of-life. +- Add missing dependency on hostname. +- Remove webpack to reduce security vulnerabilities. * Fri Oct 25 2024 KasmTech - 1.3.3-1 - Allow disabling IP blacklist - Downloads API for detailed file downloads information diff --git a/oracle/kasmvncserver.spec b/oracle/kasmvncserver.spec index 15344ba..dd8a302 100644 --- a/oracle/kasmvncserver.spec +++ b/oracle/kasmvncserver.spec @@ -83,7 +83,10 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1; %changelog * Thu Mar 20 2025 KasmTech - 1.3.4-1 -- Upstream release +- Add configuration key network.udp.payload_size. +- Remove support for distro versions that reached end-of-life. +- Add missing dependency on hostname. +- Remove webpack to reduce security vulnerabilities. * Fri Oct 25 2024 KasmTech - 1.3.3-1 - Allow disabling IP blacklist - Downloads API for detailed file downloads information diff --git a/oracle/kasmvncserver9.spec b/oracle/kasmvncserver9.spec index 40dd966..b317506 100644 --- a/oracle/kasmvncserver9.spec +++ b/oracle/kasmvncserver9.spec @@ -83,7 +83,10 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1; %changelog * Thu Mar 20 2025 KasmTech - 1.3.4-1 -- Upstream release +- Add configuration key network.udp.payload_size. +- Remove support for distro versions that reached end-of-life. +- Add missing dependency on hostname. +- Remove webpack to reduce security vulnerabilities. * Fri Oct 25 2024 KasmTech - 1.3.3-1 - Allow disabling IP blacklist - Downloads API for detailed file downloads information From 6f13eac2d75edaabc8528eecbb95811cba4d3bb8 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Mon, 24 Mar 2025 17:26:46 +1300 Subject: [PATCH 082/167] KASM-7051 Fill release notes for deb and rpm --- debian/changelog | 1 + fedora/kasmvncserver.spec | 1 + opensuse/kasmvncserver.spec | 1 + oracle/kasmvncserver.spec | 1 + oracle/kasmvncserver9.spec | 1 + 5 files changed, 5 insertions(+) diff --git a/debian/changelog b/debian/changelog index 19f0a73..3cb1e97 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,7 @@ kasmvnc (1.3.4-1) unstable; urgency=medium * Remove support for distro versions that reached end-of-life. * Add missing dependency on libdatetime-perl. * Remove webpack to reduce security vulnerabilities. + * Special characters in filenames are now properly escaped, preventing invalid JSON. -- Kasm Technologies LLC Thu, 20 Mar 2025 03:21:46 +0000 diff --git a/fedora/kasmvncserver.spec b/fedora/kasmvncserver.spec index f3873fb..d9232b3 100644 --- a/fedora/kasmvncserver.spec +++ b/fedora/kasmvncserver.spec @@ -88,6 +88,7 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1; - Remove support for distro versions that reached end-of-life. - Add missing dependency on hostname. - Remove webpack to reduce security vulnerabilities. +- Special characters in filenames are now properly escaped, preventing invalid JSON. * Fri Oct 25 2024 KasmTech - 1.3.3-1 - Allow disabling IP blacklist - Downloads API for detailed file downloads information diff --git a/opensuse/kasmvncserver.spec b/opensuse/kasmvncserver.spec index cad1809..275eb21 100644 --- a/opensuse/kasmvncserver.spec +++ b/opensuse/kasmvncserver.spec @@ -86,6 +86,7 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1; - Remove support for distro versions that reached end-of-life. - Add missing dependency on hostname. - Remove webpack to reduce security vulnerabilities. +- Special characters in filenames are now properly escaped, preventing invalid JSON. * Fri Oct 25 2024 KasmTech - 1.3.3-1 - Allow disabling IP blacklist - Downloads API for detailed file downloads information diff --git a/oracle/kasmvncserver.spec b/oracle/kasmvncserver.spec index dd8a302..85751bd 100644 --- a/oracle/kasmvncserver.spec +++ b/oracle/kasmvncserver.spec @@ -87,6 +87,7 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1; - Remove support for distro versions that reached end-of-life. - Add missing dependency on hostname. - Remove webpack to reduce security vulnerabilities. +- Special characters in filenames are now properly escaped, preventing invalid JSON. * Fri Oct 25 2024 KasmTech - 1.3.3-1 - Allow disabling IP blacklist - Downloads API for detailed file downloads information diff --git a/oracle/kasmvncserver9.spec b/oracle/kasmvncserver9.spec index b317506..8611c30 100644 --- a/oracle/kasmvncserver9.spec +++ b/oracle/kasmvncserver9.spec @@ -87,6 +87,7 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1; - Remove support for distro versions that reached end-of-life. - Add missing dependency on hostname. - Remove webpack to reduce security vulnerabilities. +- Special characters in filenames are now properly escaped, preventing invalid JSON. * Fri Oct 25 2024 KasmTech - 1.3.3-1 - Allow disabling IP blacklist - Downloads API for detailed file downloads information From e647af5e281735d1c7fc676ca089201aeae7130a Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 24 Mar 2025 12:18:11 +0000 Subject: [PATCH 083/167] Update novnc ref --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index e43a13a..74a470e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "kasmweb"] path = kasmweb url = https://github.com/kasmtech/noVNC.git - branch = master + branch = release/1.2.3 From 0017991a5512939ca823287dd4d0e0d3ddb97b8e Mon Sep 17 00:00:00 2001 From: "ryan.kuba" Date: Tue, 11 Feb 2025 09:51:18 -0500 Subject: [PATCH 084/167] KASM-6788 use thread and future instead of openmp for image encoding --- common/rfb/EncodeManager.cxx | 41 ++++++++++++++++++++++++++++-------- common/rfb/EncodeManager.h | 3 ++- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index 1cbd32d..5730352 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -22,6 +22,12 @@ #include #include +#include +#include +#include +#include + + #include #include #include @@ -210,6 +216,7 @@ EncodeManager::EncodeManager(SConnection* conn_, EncCache *encCache_) : conn(con dynamicQualityMin = Server::dynamicQualityMin; dynamicQualityOff = Server::dynamicQualityMax - Server::dynamicQualityMin; } + std::atomic webpTookTooLong{false}; } EncodeManager::~EncodeManager() @@ -886,8 +893,7 @@ void EncodeManager::checkWebpFallback(const struct timeval *start) { unsigned us; us = msSince(start) * 1024; if (us > webpFallbackUs) - #pragma omp atomic - webpTookTooLong |= true; + webpTookTooLong = true; } } @@ -1130,8 +1136,10 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb, std::vector ms; uint32_t i; - if (rfb::Server::rectThreads > 0) - omp_set_num_threads(rfb::Server::rectThreads); + int num_threads = std::thread::hardware_concurrency(); + if (rfb::Server::rectThreads > 0) { + num_threads = rfb::Server::rectThreads; + } webpTookTooLong = false; changed.get_rects(&rects); @@ -1249,12 +1257,27 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb, } scalingTime = msSince(&scalestart); - #pragma omp parallel for schedule(dynamic, 1) + std::vector> futures; + futures.reserve(subrects.size()); for (i = 0; i < subrects.size(); ++i) { - encoderTypes[i] = getEncoderType(subrects[i], pb, &palettes[i], compresseds[i], - &isWebp[i], &fromCache[i], - scaledpb, scaledrects[i], ms[i]); - checkWebpFallback(start); + Rect subrect = subrects[i]; + const PixelBuffer* current_pb = pb; + uint8_t* current_encoderTypes = &encoderTypes[i]; + uint8_t* current_fromCache = &fromCache[i]; + const PixelBuffer* current_scaledpb = scaledpb; + Rect current_scaledrect = scaledrects[i]; + uint32_t* current_ms = &ms[i]; + const struct timeval* current_start = start; + auto task = [this, subrect, current_pb, &palettes, &compresseds, &isWebp, current_encoderTypes, current_fromCache, current_scaledpb, current_scaledrect, current_ms, current_start, i]() { + *current_encoderTypes = getEncoderType(subrect, current_pb, &palettes[i], compresseds[i], + &isWebp[i], current_fromCache, + current_scaledpb, current_scaledrect, *current_ms); + checkWebpFallback(current_start); + }; + futures.push_back(std::async(std::launch::async, task)); + } + for (auto& future : futures) { + future.get(); } for (i = 0; i < subrects.size(); ++i) { diff --git a/common/rfb/EncodeManager.h b/common/rfb/EncodeManager.h index 20ba837..7ff24bf 100644 --- a/common/rfb/EncodeManager.h +++ b/common/rfb/EncodeManager.h @@ -32,6 +32,7 @@ #include #include +#include #include namespace rfb { @@ -199,7 +200,7 @@ namespace rfb { size_t curMaxUpdateSize; unsigned webpFallbackUs; unsigned webpBenchResult; - bool webpTookTooLong; + std::atomic webpTookTooLong; unsigned encodingTime; unsigned maxEncodingTime, framesSinceEncPrint; unsigned scalingTime; From 84aa133511ccaf3c71df30b9f988980757e87263 Mon Sep 17 00:00:00 2001 From: El Date: Fri, 7 Mar 2025 01:04:46 +0500 Subject: [PATCH 085/167] KASM-6788 Refactor EncodeManager to use std::execution with parallel algorithms. Removes OpenMP dependency, improves atomic usage, and fixes various minor code quality issues including initialization and memory management --- common/rfb/EncodeManager.cxx | 117 ++++++++++++++--------------------- common/rfb/EncodeManager.h | 18 +++--- 2 files changed, 55 insertions(+), 80 deletions(-) diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index 5730352..5e94cdc 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -19,14 +19,7 @@ * USA. */ -#include -#include - -#include -#include -#include -#include - +#include #include #include @@ -50,6 +43,7 @@ #include #include #include +#include using namespace rfb; @@ -99,9 +93,9 @@ struct RectInfo { }; struct QualityInfo { - struct timeval lastUpdate; + struct timeval lastUpdate{}; Rect rect; - unsigned score; + unsigned score{}; }; }; @@ -216,7 +210,6 @@ EncodeManager::EncodeManager(SConnection* conn_, EncCache *encCache_) : conn(con dynamicQualityMin = Server::dynamicQualityMin; dynamicQualityOff = Server::dynamicQualityMax - Server::dynamicQualityMin; } - std::atomic webpTookTooLong{false}; } EncodeManager::~EncodeManager() @@ -887,13 +880,12 @@ void EncodeManager::findSolidRect(const Rect& rect, Region *changed, } } -void EncodeManager::checkWebpFallback(const struct timeval *start) { +void EncodeManager::checkWebpFallback(const timeval *start) { // Have we taken too long for the frame? If so, drop from WEBP to JPEG - if (start && activeEncoders[encoderFullColour] == encoderTightWEBP && !webpTookTooLong) { - unsigned us; - us = msSince(start) * 1024; + if (start && activeEncoders[encoderFullColour] == encoderTightWEBP && !webpTookTooLong.load(std::memory_order_relaxed)) { + const auto us = msSince(start) * 1024; if (us > webpFallbackUs) - webpTookTooLong = true; + webpTookTooLong.store(true, std::memory_order_relaxed); } } @@ -1128,20 +1120,13 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb, const bool mainScreen) { std::vector rects, subrects, scaledrects; - std::vector::const_iterator rect; std::vector encoderTypes; std::vector isWebp, fromCache; std::vector palettes; std::vector > compresseds; std::vector ms; - uint32_t i; - int num_threads = std::thread::hardware_concurrency(); - if (rfb::Server::rectThreads > 0) { - num_threads = rfb::Server::rectThreads; - } - - webpTookTooLong = false; + webpTookTooLong.store(false, std::memory_order_relaxed); changed.get_rects(&rects); // Update stats @@ -1156,18 +1141,18 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb, subrects.reserve(rects.size() * 1.5f); - for (rect = rects.begin(); rect != rects.end(); ++rect) { - int w, h, sw, sh; + for (const auto& rect : rects) { + int sw, sh; Rect sr; - w = rect->width(); - h = rect->height(); + const auto w = rect.width(); + const auto h = rect.height(); // No split necessary? if ((((w*h) < SubRectMaxArea) && (w < SubRectMaxWidth)) || (videoDetected && !encoders[encoderTightWEBP]->isSupported())) { - subrects.push_back(*rect); - trackRectQuality(*rect); + subrects.push_back(rect); + trackRectQuality(rect); continue; } @@ -1178,15 +1163,15 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb, sh = SubRectMaxArea / sw; - for (sr.tl.y = rect->tl.y; sr.tl.y < rect->br.y; sr.tl.y += sh) { + for (sr.tl.y = rect.tl.y; sr.tl.y < rect.br.y; sr.tl.y += sh) { sr.br.y = sr.tl.y + sh; - if (sr.br.y > rect->br.y) - sr.br.y = rect->br.y; + if (sr.br.y > rect.br.y) + sr.br.y = rect.br.y; - for (sr.tl.x = rect->tl.x; sr.tl.x < rect->br.x; sr.tl.x += sw) { + for (sr.tl.x = rect.tl.x; sr.tl.x < rect.br.x; sr.tl.x += sw) { sr.br.x = sr.tl.x + sw; - if (sr.br.x > rect->br.x) - sr.br.x = rect->br.x; + if (sr.br.x > rect.br.x) + sr.br.x = rect.br.x; subrects.push_back(sr); trackRectQuality(sr); @@ -1194,13 +1179,18 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb, } } - encoderTypes.resize(subrects.size()); - isWebp.resize(subrects.size()); - fromCache.resize(subrects.size()); - palettes.resize(subrects.size()); - compresseds.resize(subrects.size()); - scaledrects.resize(subrects.size()); - ms.resize(subrects.size()); + const size_t subrects_size = subrects.size(); + + std::vector indices(subrects_size); + std::iota(std::begin(indices), std::end(indices), 0); + + encoderTypes.resize(subrects_size); + isWebp.resize(subrects_size); + fromCache.resize(subrects_size); + palettes.resize(subrects_size); + compresseds.resize(subrects_size); + scaledrects.resize(subrects_size); + ms.resize(subrects_size); // In case the current resolution is above the max video res, and video was detected, // scale to that res, keeping aspect ratio @@ -1232,7 +1222,7 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb, break; } - for (i = 0; i < subrects.size(); ++i) { + for (uint32_t i = 0; i < subrects_size; ++i) { const Rect old = scaledrects[i] = subrects[i]; scaledrects[i].br.x *= diff; scaledrects[i].br.y *= diff; @@ -1257,30 +1247,15 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb, } scalingTime = msSince(&scalestart); - std::vector> futures; - futures.reserve(subrects.size()); - for (i = 0; i < subrects.size(); ++i) { - Rect subrect = subrects[i]; - const PixelBuffer* current_pb = pb; - uint8_t* current_encoderTypes = &encoderTypes[i]; - uint8_t* current_fromCache = &fromCache[i]; - const PixelBuffer* current_scaledpb = scaledpb; - Rect current_scaledrect = scaledrects[i]; - uint32_t* current_ms = &ms[i]; - const struct timeval* current_start = start; - auto task = [this, subrect, current_pb, &palettes, &compresseds, &isWebp, current_encoderTypes, current_fromCache, current_scaledpb, current_scaledrect, current_ms, current_start, i]() { - *current_encoderTypes = getEncoderType(subrect, current_pb, &palettes[i], compresseds[i], - &isWebp[i], current_fromCache, - current_scaledpb, current_scaledrect, *current_ms); - checkWebpFallback(current_start); - }; - futures.push_back(std::async(std::launch::async, task)); - } - for (auto& future : futures) { - future.get(); - } + std::for_each(std::execution::par_unseq, std::begin(indices), std::end(indices), [&](size_t i) + { + encoderTypes[i] = getEncoderType(subrects[i], pb, &palettes[i], compresseds[i], + &isWebp[i], &fromCache[i], + scaledpb, scaledrects[i], ms[i]); + checkWebpFallback(start); + }); - for (i = 0; i < subrects.size(); ++i) { + for (uint32_t i = 0; i < subrects_size; ++i) { if (encoderTypes[i] == encoderFullColour) { if (isWebp[i]) webpstats.ms += ms[i]; @@ -1292,7 +1267,7 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb, if (start) { encodingTime = msSince(start); - if (vlog.getLevel() >= vlog.LEVEL_DEBUG) { + if (vlog.getLevel() >= rfb::LogWriter::LEVEL_DEBUG) { framesSinceEncPrint++; if (maxEncodingTime < encodingTime) maxEncodingTime = encodingTime; @@ -1307,11 +1282,11 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb, } } - if (webpTookTooLong) + if (webpTookTooLong.load(std::memory_order_relaxed)) activeEncoders[encoderFullColour] = encoderTightJPEG; - for (i = 0; i < subrects.size(); ++i) { - if (encCache->enabled && compresseds[i].size() && !fromCache[i] && + for (uint32_t i = 0; i < subrects_size; ++i) { + if (encCache->enabled && !compresseds[i].empty() && !fromCache[i] && !encoders[encoderTightQOI]->isSupported()) { void *tmp = malloc(compresseds[i].size()); memcpy(tmp, &compresseds[i][0], compresseds[i].size()); diff --git a/common/rfb/EncodeManager.h b/common/rfb/EncodeManager.h index 7ff24bf..7844faa 100644 --- a/common/rfb/EncodeManager.h +++ b/common/rfb/EncodeManager.h @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -51,7 +50,7 @@ namespace rfb { class EncodeManager: public Timer::Callback { public: EncodeManager(SConnection* conn, EncCache *encCache); - ~EncodeManager(); + ~EncodeManager() override; void logStats(); @@ -73,10 +72,10 @@ namespace rfb { encodingTime = 0; }; - unsigned getEncodingTime() const { + [[nodiscard]] unsigned getEncodingTime() const { return encodingTime; }; - unsigned getScalingTime() const { + [[nodiscard]] unsigned getScalingTime() const { return scalingTime; }; @@ -125,7 +124,8 @@ namespace rfb { uint8_t *fromCache, const PixelBuffer *scaledpb, const Rect& scaledrect, uint32_t &ms) const; - virtual bool handleTimeout(Timer* t); + + bool handleTimeout(Timer* t) override; bool checkSolidTile(const Rect& r, const rdr::U8* colourValue, const PixelBuffer *pb); @@ -200,7 +200,7 @@ namespace rfb { size_t curMaxUpdateSize; unsigned webpFallbackUs; unsigned webpBenchResult; - std::atomic webpTookTooLong; + std::atomic webpTookTooLong{false}; unsigned encodingTime; unsigned maxEncodingTime, framesSinceEncPrint; unsigned scalingTime; @@ -209,14 +209,14 @@ namespace rfb { class OffsetPixelBuffer : public FullFramePixelBuffer { public: - OffsetPixelBuffer() {} - virtual ~OffsetPixelBuffer() {} + OffsetPixelBuffer() = default; + ~OffsetPixelBuffer() override = default; void update(const PixelFormat& pf, int width, int height, const rdr::U8* data_, int stride); private: - virtual rdr::U8* getBufferRW(const Rect& r, int* stride); + rdr::U8* getBufferRW(const Rect& r, int* stride) override; }; }; From 59792ee93c674a6dbddbf17531c2661a7e3c7afb Mon Sep 17 00:00:00 2001 From: El Date: Fri, 7 Mar 2025 01:05:32 +0500 Subject: [PATCH 086/167] KASM-6788 Updates CMake configuration to use C++20 standard --- CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c3bded..96c566e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,13 +74,10 @@ set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -UNDEBUG") # Make sure we get a sane C version set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") +set(CMAKE_CXX_STANDARD 20) # Enable OpenMP set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") - -# Enable C++ 11 -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") # Tell the compiler to be stringent set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wformat=2") From f54ec77e440f7334af0506840f8e620eac3d0a26 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 20 Mar 2025 05:51:18 +0500 Subject: [PATCH 087/167] KASM-6788 Specify C and CXX languages in the project() definition for better clarity and compatibility. Additionally, link the TBB library for builds using GCC versions earlier than 10 to address dependency requirements --- CMakeLists.txt | 2 +- common/rfb/CMakeLists.txt | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 96c566e..22f21dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ include(CheckCSourceRuns) include(CMakeMacroLibtoolFile) -project(kasmvnc) +project(kasmvnc LANGUAGES C CXX) set(VERSION 0.9) # The RC version must always be four comma-separated numbers diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt index 905e76e..88936bc 100644 --- a/common/rfb/CMakeLists.txt +++ b/common/rfb/CMakeLists.txt @@ -82,6 +82,12 @@ endif(WIN32) set(RFB_LIBRARIES ${JPEG_LIBRARIES} ${PNG_LIBRARIES} os rdr Xregion) +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10) + set(RFB_LIBRARIES ${RFB_LIBRARIES} tbb) + endif () +endif () + if(HAVE_PAM) set(RFB_SOURCES ${RFB_SOURCES} UnixPasswordValidator.cxx UnixPasswordValidator.h pam.c pam.h) From 4ea5f734ec4a36db1c16858759e1207ee92e0161 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 20 Mar 2025 14:58:29 +0500 Subject: [PATCH 088/167] KASM-6788 Switch to gcc14-c++ on openSUSE and add libtbb-dev for Ubuntu Focal --- builder/dockerfile.opensuse_15.build | 4 +++- builder/dockerfile.ubuntu_focal.build | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/builder/dockerfile.opensuse_15.build b/builder/dockerfile.opensuse_15.build index db2f130..3d4cfe3 100644 --- a/builder/dockerfile.opensuse_15.build +++ b/builder/dockerfile.opensuse_15.build @@ -14,7 +14,7 @@ RUN zypper install -ny \ fonttosfnt \ font-util \ gcc \ - gcc-c++ \ + gcc14-c++ \ giflib-devel \ git \ gzip \ @@ -45,6 +45,8 @@ RUN zypper install -ny \ xorg-x11-util-devel \ zlib-devel +RUN update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-14 100 + ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR RUN $SCRIPTS_DIR/build-webp diff --git a/builder/dockerfile.ubuntu_focal.build b/builder/dockerfile.ubuntu_focal.build index c734715..1e356b0 100644 --- a/builder/dockerfile.ubuntu_focal.build +++ b/builder/dockerfile.ubuntu_focal.build @@ -13,7 +13,7 @@ RUN apt-get update && \ RUN apt-get update && apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev RUN apt-get update && apt-get -y install cmake git vim wget curl -RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev +RUN apt-get update && apt-get -y install libtbb-dev libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR From b3f2dd1196dbd87f4ec07283b317b48e2d6fa4b5 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 20 Mar 2025 18:46:33 +0500 Subject: [PATCH 089/167] KASM-6788 Update Dockerfiles to use GCC Toolset 14 and add libSM-devel --- builder/dockerfile.opensuse_15.build | 2 +- builder/dockerfile.oracle_8.build | 6 +++++- builder/dockerfile.oracle_9.build | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/builder/dockerfile.opensuse_15.build b/builder/dockerfile.opensuse_15.build index 3d4cfe3..2a4b5ec 100644 --- a/builder/dockerfile.opensuse_15.build +++ b/builder/dockerfile.opensuse_15.build @@ -13,7 +13,7 @@ RUN zypper install -ny \ ffmpeg-4-libavcodec-devel \ fonttosfnt \ font-util \ - gcc \ + gcc14 \ gcc14-c++ \ giflib-devel \ git \ diff --git a/builder/dockerfile.oracle_8.build b/builder/dockerfile.oracle_8.build index 4a98a19..4aa7e5b 100644 --- a/builder/dockerfile.oracle_8.build +++ b/builder/dockerfile.oracle_8.build @@ -15,6 +15,7 @@ RUN \ dnf-plugins-core \ gcc \ gcc-c++ \ + gcc-toolset-14 \ git \ gnutls-devel \ libjpeg-turbo-devel \ @@ -48,7 +49,10 @@ RUN dnf install -y \ xorg-x11-xtrans-devel \ libXrandr-devel \ libXtst-devel \ - libXcursor-devel + libXcursor-devel \ + libSM-devel + +RUN scl enable gcc-toolset-14 bash ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR diff --git a/builder/dockerfile.oracle_9.build b/builder/dockerfile.oracle_9.build index ca94b69..41f5830 100644 --- a/builder/dockerfile.oracle_9.build +++ b/builder/dockerfile.oracle_9.build @@ -15,6 +15,7 @@ RUN \ dnf-plugins-core \ gcc \ gcc-c++ \ + gcc-toolset-14 \ git \ gnutls-devel \ libjpeg-turbo-devel \ @@ -47,7 +48,10 @@ RUN dnf install -y \ xorg-x11-xtrans-devel \ libXrandr-devel \ libXtst-devel \ - libXcursor-devel + libXcursor-devel \ + libSM-devel + +RUN scl enable gcc-toolset-14 bash ENV SCRIPTS_DIR=/tmp/scripts From aa40f59af52d6b9e21788e3670e7607ffc302574 Mon Sep 17 00:00:00 2001 From: El Date: Sat, 22 Mar 2025 23:22:16 +0500 Subject: [PATCH 090/167] KASM-6788 Add TBB dependency for EL8 platform and older GCC versions --- common/rfb/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt index 88936bc..70217fe 100644 --- a/common/rfb/CMakeLists.txt +++ b/common/rfb/CMakeLists.txt @@ -82,10 +82,10 @@ endif(WIN32) set(RFB_LIBRARIES ${JPEG_LIBRARIES} ${PNG_LIBRARIES} os rdr Xregion) -if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10) - set(RFB_LIBRARIES ${RFB_LIBRARIES} tbb) - endif () +cmake_host_system_information(RESULT DISTRO QUERY DISTRIB_INFO) +if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10) OR +(DISTRO_PLATFORM_ID MATCHES "platform:el8")) + set(RFB_LIBRARIES ${RFB_LIBRARIES} tbb) endif () if(HAVE_PAM) From 7eddf5fd65b3cc48a165258117f0a1139bbacd09 Mon Sep 17 00:00:00 2001 From: El Date: Sun, 23 Mar 2025 15:11:24 +0500 Subject: [PATCH 091/167] KASM-6788 Update Dockerfile to install CMake from source --- builder/dockerfile.debian_bullseye.build | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/builder/dockerfile.debian_bullseye.build b/builder/dockerfile.debian_bullseye.build index f626bb7..077a2e5 100644 --- a/builder/dockerfile.debian_bullseye.build +++ b/builder/dockerfile.debian_bullseye.build @@ -12,9 +12,22 @@ RUN apt-get update && \ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev -RUN apt-get update && apt-get -y install cmake git libgnutls28-dev vim wget tightvncserver curl +RUN apt-get update && apt-get -y install git libgnutls28-dev vim wget tightvncserver curl RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev +RUN CMAKE_URL="https://cmake.org/files/v3.22/cmake-3.22.0" && \ + ARCH=$(arch) && \ + if [ "$ARCH" = "x86_64" ]; then \ + CMAKE_URL="${CMAKE_URL}-linux-x86_64.sh"; \ + elif [ "$ARCH" = "aarch64" ]; then \ + CMAKE_URL="${CMAKE_URL}-linux-aarch64.sh"; \ + else \ + echo "Unsupported architecture: $ARCH" && exit 1; \ + fi && \ + curl -fsSL $CMAKE_URL -o cmake.sh && \ + (echo y; echo n) | bash cmake.sh --prefix=/usr/local --skip-license && \ + rm cmake.sh + ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR RUN $SCRIPTS_DIR/build-webp From 130c7fef9346826f0ec608f5b3aeb18f3a9f733a Mon Sep 17 00:00:00 2001 From: El Date: Sun, 23 Mar 2025 15:44:20 +0500 Subject: [PATCH 092/167] KASM-6788 Update Dockerfile to install CMake from source --- builder/dockerfile.opensuse_15.build | 13 +++++++++++++ builder/dockerfile.ubuntu_focal.build | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/builder/dockerfile.opensuse_15.build b/builder/dockerfile.opensuse_15.build index 2a4b5ec..4bbb558 100644 --- a/builder/dockerfile.opensuse_15.build +++ b/builder/dockerfile.opensuse_15.build @@ -56,6 +56,19 @@ RUN useradd -u 1000 docker && \ groupadd -g 1000 docker && \ usermod -a -G docker docker +RUN ARCH=$(arch) && \ + CMAKE_URL="https://cmake.org/files/v3.22/cmake-3.22.0" && \ + if [ "$ARCH" = "x86_64" ]; then \ + CMAKE_URL="${CMAKE_URL}-linux-x86_64.sh"; \ + elif [ "$ARCH" = "aarch64" ]; then \ + CMAKE_URL="${CMAKE_URL}-linux-aarch64.sh"; \ + else \ + echo "Unsupported architecture: $ARCH" && exit 1; \ + fi && \ + curl -fsSL $CMAKE_URL -o cmake.sh && \ + (echo y; echo n) | bash cmake.sh --prefix=/usr/local --skip-license && \ + rm cmake.sh + COPY --chown=docker:docker . /src/ diff --git a/builder/dockerfile.ubuntu_focal.build b/builder/dockerfile.ubuntu_focal.build index 1e356b0..bdfad4c 100644 --- a/builder/dockerfile.ubuntu_focal.build +++ b/builder/dockerfile.ubuntu_focal.build @@ -22,6 +22,19 @@ RUN $SCRIPTS_DIR/build-libjpeg-turbo RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo +RUN ARCH=$(arch) && \ + CMAKE_URL="https://cmake.org/files/v3.22/cmake-3.22.0" && \ + if [ "$ARCH" = "x86_64" ]; then \ + CMAKE_URL="${CMAKE_URL}-linux-x86_64.sh"; \ + elif [ "$ARCH" = "aarch64" ]; then \ + CMAKE_URL="${CMAKE_URL}-linux-aarch64.sh"; \ + else \ + echo "Unsupported architecture: $ARCH" && exit 1; \ + fi && \ + curl -fsSL $CMAKE_URL -o cmake.sh && \ + (echo y; echo n) | bash cmake.sh --prefix=/usr/local --skip-license && \ + rm cmake.sh + COPY --chown=docker:docker . /src/ USER docker From 4284f8f8a6937b6813c5920a7cf22e0e28f4a4fe Mon Sep 17 00:00:00 2001 From: El Date: Sun, 23 Mar 2025 16:37:28 +0500 Subject: [PATCH 093/167] KASM-6788 Refactor Dockerfile to streamline build process --- builder/dockerfile.oracle_8.build | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/builder/dockerfile.oracle_8.build b/builder/dockerfile.oracle_8.build index 4aa7e5b..f28c1df 100644 --- a/builder/dockerfile.oracle_8.build +++ b/builder/dockerfile.oracle_8.build @@ -39,6 +39,7 @@ RUN dnf install -y --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion- # Install from new repos RUN dnf install -y \ + tbb-devel \ ffmpeg-devel \ giflib-devel \ lbzip2 \ @@ -52,16 +53,13 @@ RUN dnf install -y \ libXcursor-devel \ libSM-devel -RUN scl enable gcc-toolset-14 bash - ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR -RUN $SCRIPTS_DIR/build-webp -RUN $SCRIPTS_DIR/build-libjpeg-turbo - -RUN useradd -m docker && echo "docker:docker" | chpasswd +RUN echo "source /opt/rh/gcc-toolset-14/enable" > /etc/profile.d/gcc-toolset.sh && \ + $SCRIPTS_DIR/build-webp && $SCRIPTS_DIR/build-libjpeg-turbo && \ + useradd -m docker && echo "docker:docker" | chpasswd COPY --chown=docker:docker . /src/ USER docker -ENTRYPOINT ["/src/builder/build.sh"] +ENTRYPOINT ["bash", "-l", "-c", "/src/builder/build.sh"] From 4091cc3ae6e83b3b6b6175b3962be8c802c8e65d Mon Sep 17 00:00:00 2001 From: El Date: Sun, 23 Mar 2025 19:24:59 +0500 Subject: [PATCH 094/167] KASM-6788 Refactor Dockerfile to streamline build process --- builder/dockerfile.ubuntu_focal.deb.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/dockerfile.ubuntu_focal.deb.build b/builder/dockerfile.ubuntu_focal.deb.build index 8a4db12..ffe6402 100644 --- a/builder/dockerfile.ubuntu_focal.deb.build +++ b/builder/dockerfile.ubuntu_focal.deb.build @@ -3,7 +3,7 @@ FROM ubuntu:focal ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs + apt-get -y install vim build-essential devscripts equivs libtbb-dev # Install build-deps for the package. COPY ./debian/control /tmp From 90c38a0da8ac5ce861ee3fec639996e723417e12 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 24 Mar 2025 16:07:18 +0500 Subject: [PATCH 095/167] KASM-6788 Refactor Dockerfile to streamline build process --- builder/dockerfile.opensuse_15.build | 12 +++++------- builder/dockerfile.oracle_9.build | 12 ++++-------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/builder/dockerfile.opensuse_15.build b/builder/dockerfile.opensuse_15.build index 4bbb558..954ada8 100644 --- a/builder/dockerfile.opensuse_15.build +++ b/builder/dockerfile.opensuse_15.build @@ -47,11 +47,6 @@ RUN zypper install -ny \ RUN update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-14 100 -ENV SCRIPTS_DIR=/tmp/scripts -COPY builder/scripts $SCRIPTS_DIR -RUN $SCRIPTS_DIR/build-webp -RUN $SCRIPTS_DIR/build-libjpeg-turbo - RUN useradd -u 1000 docker && \ groupadd -g 1000 docker && \ usermod -a -G docker docker @@ -69,8 +64,11 @@ RUN ARCH=$(arch) && \ (echo y; echo n) | bash cmake.sh --prefix=/usr/local --skip-license && \ rm cmake.sh +ENV SCRIPTS_DIR=/tmp/scripts +COPY builder/scripts $SCRIPTS_DIR +RUN $SCRIPTS_DIR/build-webp && $SCRIPTS_DIR/build-libjpeg-turbo + COPY --chown=docker:docker . /src/ - USER docker -ENTRYPOINT ["/src/builder/build.sh"] +ENTRYPOINT ["bash", "-l", "-c", "/src/builder/build.sh"] diff --git a/builder/dockerfile.oracle_9.build b/builder/dockerfile.oracle_9.build index 41f5830..ca6e705 100644 --- a/builder/dockerfile.oracle_9.build +++ b/builder/dockerfile.oracle_9.build @@ -51,17 +51,13 @@ RUN dnf install -y \ libXcursor-devel \ libSM-devel -RUN scl enable gcc-toolset-14 bash - - ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR -RUN $SCRIPTS_DIR/build-webp -RUN $SCRIPTS_DIR/build-libjpeg-turbo - -RUN useradd -m docker && echo "docker:docker" | chpasswd +RUN echo "source /opt/rh/gcc-toolset-14/enable" > /etc/profile.d/gcc-toolset.sh && \ + $SCRIPTS_DIR/build-webp && $SCRIPTS_DIR/build-libjpeg-turbo && \ + useradd -m docker && echo "docker:docker" | chpasswd COPY --chown=docker:docker . /src/ USER docker -ENTRYPOINT ["/src/builder/build.sh"] +ENTRYPOINT ["bash", "-l", "-c", "/src/builder/build.sh"] From 5c6e913fcab7653d36e47a05075ea3fb6750b7aa Mon Sep 17 00:00:00 2001 From: Rodwin Spruel Date: Mon, 14 Apr 2025 23:29:41 +0000 Subject: [PATCH 096/167] upgrading to libwebp 1.5.0 abd adding sharpyuv and an included library based on the change in how it is included with libwebp --- builder/scripts/build-webp | 4 ++-- unix/xserver/hw/vnc/Makefile.am | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builder/scripts/build-webp b/builder/scripts/build-webp index a6b2fd0..1254230 100755 --- a/builder/scripts/build-webp +++ b/builder/scripts/build-webp @@ -2,7 +2,7 @@ set -euo pipefail -WEBP_VERSION="1.2.4" +WEBP_VERSION="1.5.0" WEBP_TAR_URL="https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-${WEBP_VERSION}.tar.gz" WEBP_TAR_FILE="/tmp/libwebp-${WEBP_VERSION}.tar.gz" WEBP_SRC_DIR="/tmp/libwebp-${WEBP_VERSION}" @@ -21,7 +21,7 @@ prepare_source() { build_and_install() { export MAKEFLAGS=-j$(nproc) - ./configure --enable-static --disable-shared + ./configure --enable-static --disable-shared --enable-threading --enable-sse2 make make install } diff --git a/unix/xserver/hw/vnc/Makefile.am b/unix/xserver/hw/vnc/Makefile.am index a25d214..c3226eb 100644 --- a/unix/xserver/hw/vnc/Makefile.am +++ b/unix/xserver/hw/vnc/Makefile.am @@ -52,7 +52,7 @@ Xvnc_CPPFLAGS = $(XVNC_CPPFLAGS) -DKASMVNC -DNO_MODULE_EXTS \ -I$(top_srcdir)/dri3 @LIBDRM_CFLAGS@ Xvnc_LDADD = $(XVNC_LIBS) libvnccommon.la $(COMMON_LIBS) \ - $(XSERVER_LIBS) $(XSERVER_SYS_LIBS) $(XVNC_SYS_LIBS) -lX11 -lwebp -lssl -lcrypto -lcrypt \ + $(XSERVER_LIBS) $(XSERVER_SYS_LIBS) $(XVNC_SYS_LIBS) -lX11 -lwebp -lsharpyuv -lssl -lcrypto -lcrypt \ -lfreetype Xvnc_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG) -fopenmp From fd78b3fe62730f8334fb567e9ca23165e4b0f9e1 Mon Sep 17 00:00:00 2001 From: Rodwin Spruel Date: Tue, 15 Apr 2025 23:16:01 +0000 Subject: [PATCH 097/167] updaing opensuse docker file to --- builder/dockerfile.opensuse_15.build | 5 ++++- builder/scripts/build-webp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/builder/dockerfile.opensuse_15.build b/builder/dockerfile.opensuse_15.build index 954ada8..800c752 100644 --- a/builder/dockerfile.opensuse_15.build +++ b/builder/dockerfile.opensuse_15.build @@ -45,7 +45,10 @@ RUN zypper install -ny \ xorg-x11-util-devel \ zlib-devel -RUN update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-14 100 +RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 140 \ + --slave /usr/bin/g++ g++ /usr/bin/g++-14 \ + --slave /usr/bin/gcov gcov /usr/bin/gcov-14 + RUN useradd -u 1000 docker && \ groupadd -g 1000 docker && \ diff --git a/builder/scripts/build-webp b/builder/scripts/build-webp index 1254230..e5e19f1 100755 --- a/builder/scripts/build-webp +++ b/builder/scripts/build-webp @@ -21,7 +21,7 @@ prepare_source() { build_and_install() { export MAKEFLAGS=-j$(nproc) - ./configure --enable-static --disable-shared --enable-threading --enable-sse2 + ./configure --enable-static --disable-shared --enable-threading --enable-sse2 --enable-neon make make install } From c2b9721fdc2b35b063d4f1bd61f0c619b8e6c5bd Mon Sep 17 00:00:00 2001 From: El Date: Wed, 5 Mar 2025 15:41:05 +0500 Subject: [PATCH 098/167] KASM-7194 Removed package installation from this script since they're already included in the Docker image. Switched to Ninja for faster builds --- builder/scripts/build-libjpeg-turbo | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/builder/scripts/build-libjpeg-turbo b/builder/scripts/build-libjpeg-turbo index 13d1f3f..ed8a737 100755 --- a/builder/scripts/build-libjpeg-turbo +++ b/builder/scripts/build-libjpeg-turbo @@ -3,20 +3,8 @@ set -euo pipefail build_and_install() { - export MAKEFLAGS=-j`nproc` - export CFLAGS="-fpic" - cmake -DCMAKE_INSTALL_PREFIX=/usr/local -G"Unix Makefiles" - make - make install -} - -install_build_dependencies() { - install_packages cmake gcc - ensure_libjpeg_is_fast -} - -ensure_libjpeg_is_fast() { - install_packages nasm + cmake -B build -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_POSITION_INDEPENDENT_CODE=ON -GNinja . + ninja -C build install } prepare_libjpeg_source() { @@ -32,6 +20,5 @@ prepare_libjpeg_source() { source_dir=$(dirname "$0") . "$source_dir/common.sh" -install_build_dependencies prepare_libjpeg_source build_and_install From f38ad7122cf25d129fab0f8fe84c37d9bc36ddae Mon Sep 17 00:00:00 2001 From: El Date: Wed, 5 Mar 2025 15:41:54 +0500 Subject: [PATCH 099/167] KASM-7194 Fixed a typo --- BUILDING.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILDING.txt b/BUILDING.txt index 4bfaa3f..34b6ab8 100644 --- a/BUILDING.txt +++ b/BUILDING.txt @@ -91,7 +91,7 @@ npm run build # <-- only run this on subsequent changes to front-end code cd .. # build dependencies sudo builder/scripts/build-webp -sudo builder/scripts/build-build-libjpeg-turbo +sudo builder/scripts/build-libjpeg-turbo # Build KasmVNC builder/build.sh ``` From c0d73ebd28b6867f4d6bf4064956a7f340d043d1 Mon Sep 17 00:00:00 2001 From: El Date: Wed, 12 Mar 2025 21:01:52 +0500 Subject: [PATCH 100/167] KASM-7194 Add additional tools and scripts to Dockerfile for dev setup KASM-7194 Add WebP and libjpeg-turbo build scripts to Dockerfile --- builder/dockerfile.ubuntu_jammy.dev | 46 ++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/builder/dockerfile.ubuntu_jammy.dev b/builder/dockerfile.ubuntu_jammy.dev index d13638d..7201cf2 100644 --- a/builder/dockerfile.ubuntu_jammy.dev +++ b/builder/dockerfile.ubuntu_jammy.dev @@ -12,11 +12,55 @@ USER root RUN sed -i 's$# deb-src$deb-src$' /etc/apt/sources.list && \ apt update && \ - apt install -y socat sudo libxfont-dev cmake git libgnutls28-dev vim wget tightvncserver curl libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev pkg-config libfreetype6-dev libxtst-dev autoconf automake libtool xutils-dev libpixman-1-dev libxshmfence-dev libxcvt-dev libxkbfile-dev x11proto-dev libgbm-dev inotify-tools && \ + apt install -y \ + ninja-build \ + gdb \ + valgrind \ + rsync \ + dos2unix \ + socat \ + sudo \ + libxfont-dev \ + cmake \ + nasm \ + git \ + libgnutls28-dev \ + vim \ + wget \ + tightvncserver \ + curl \ + libpng-dev \ + libtiff-dev \ + libgif-dev \ + libavcodec-dev \ + libssl-dev \ + libxrandr-dev \ + libxcursor-dev \ + pkg-config \ + libfreetype6-dev \ + libxtst-dev \ + autoconf \ + automake \ + libtool \ + xutils-dev \ + libpixman-1-dev \ + libxshmfence-dev \ + libxcvt-dev \ + libxkbfile-dev \ + x11proto-dev \ + libgbm-dev \ + inotify-tools && \ echo "kasm-user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers RUN curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - RUN apt install -y nodejs + +COPY builder/scripts/build-webp /tmp +COPY builder/scripts/build-libjpeg-turbo /tmp +COPY builder/common.sh /tmp + +RUN chmod +x /tmp/build-webp && /tmp/build-webp +RUN chmod +x /tmp/build-libjpeg-turbo && /tmp/build-libjpeg-turbo USER 1000 From 62a1c210c9e795d147b2e1972b06e3903371c357 Mon Sep 17 00:00:00 2001 From: El Date: Fri, 14 Mar 2025 15:25:52 +0500 Subject: [PATCH 101/167] KASM-7194 Add NASM to all builder Dockerfiles --- builder/dockerfile.alpine_318.build | 1 + builder/dockerfile.alpine_319.build | 1 + builder/dockerfile.alpine_320.build | 1 + builder/dockerfile.alpine_321.build | 1 + builder/dockerfile.debian_bookworm.build | 2 +- builder/dockerfile.debian_bullseye.build | 2 +- builder/dockerfile.debian_buster.build | 2 +- builder/dockerfile.fedora_forty.build | 1 + builder/dockerfile.fedora_fortyone.build | 1 + builder/dockerfile.fedora_thirtynine.build | 1 + builder/dockerfile.kali_kali-rolling.build | 2 +- builder/dockerfile.opensuse_15.build | 1 + builder/dockerfile.oracle_8.build | 1 + builder/dockerfile.oracle_9.build | 1 + builder/dockerfile.ubuntu_focal.build | 7 ++++--- builder/dockerfile.ubuntu_jammy.build | 2 +- builder/dockerfile.ubuntu_noble.build | 2 +- 17 files changed, 20 insertions(+), 9 deletions(-) diff --git a/builder/dockerfile.alpine_318.build b/builder/dockerfile.alpine_318.build index 8a01ac8..b163664 100644 --- a/builder/dockerfile.alpine_318.build +++ b/builder/dockerfile.alpine_318.build @@ -14,6 +14,7 @@ RUN \ bash \ ca-certificates \ cmake \ + nasm \ coreutils \ curl \ eudev-dev \ diff --git a/builder/dockerfile.alpine_319.build b/builder/dockerfile.alpine_319.build index a73670b..c0b18b7 100644 --- a/builder/dockerfile.alpine_319.build +++ b/builder/dockerfile.alpine_319.build @@ -14,6 +14,7 @@ RUN \ bash \ ca-certificates \ cmake \ + nasm \ coreutils \ curl \ eudev-dev \ diff --git a/builder/dockerfile.alpine_320.build b/builder/dockerfile.alpine_320.build index 42995f1..8212b60 100644 --- a/builder/dockerfile.alpine_320.build +++ b/builder/dockerfile.alpine_320.build @@ -14,6 +14,7 @@ RUN \ bash \ ca-certificates \ cmake \ + nasm \ coreutils \ curl \ eudev-dev \ diff --git a/builder/dockerfile.alpine_321.build b/builder/dockerfile.alpine_321.build index e73d31f..5ccb9ac 100644 --- a/builder/dockerfile.alpine_321.build +++ b/builder/dockerfile.alpine_321.build @@ -14,6 +14,7 @@ RUN \ bash \ ca-certificates \ cmake \ + nasm \ coreutils \ curl \ eudev-dev \ diff --git a/builder/dockerfile.debian_bookworm.build b/builder/dockerfile.debian_bookworm.build index 8c0e8de..c0c9212 100644 --- a/builder/dockerfile.debian_bookworm.build +++ b/builder/dockerfile.debian_bookworm.build @@ -22,7 +22,7 @@ RUN apt-get update && \ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev -RUN apt-get update && apt-get -y install cmake git libgnutls28-dev vim wget tightvncserver curl +RUN apt-get update && apt-get -y install ninja-build cmake nasm git libgnutls28-dev vim wget tightvncserver curl RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev ENV SCRIPTS_DIR=/tmp/scripts diff --git a/builder/dockerfile.debian_bullseye.build b/builder/dockerfile.debian_bullseye.build index 077a2e5..528b179 100644 --- a/builder/dockerfile.debian_bullseye.build +++ b/builder/dockerfile.debian_bullseye.build @@ -12,7 +12,7 @@ RUN apt-get update && \ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev -RUN apt-get update && apt-get -y install git libgnutls28-dev vim wget tightvncserver curl +RUN apt-get update && apt-get -y install ninja-build nasm git libgnutls28-dev vim wget tightvncserver curl RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev RUN CMAKE_URL="https://cmake.org/files/v3.22/cmake-3.22.0" && \ diff --git a/builder/dockerfile.debian_buster.build b/builder/dockerfile.debian_buster.build index c8f8008..a1e2afd 100644 --- a/builder/dockerfile.debian_buster.build +++ b/builder/dockerfile.debian_buster.build @@ -12,7 +12,7 @@ RUN apt-get update && \ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev -RUN apt-get update && apt-get -y install cmake git libgnutls28-dev vim wget tightvncserver curl +RUN apt-get update && apt-get -y install ninja-build cmake nasm git libgnutls28-dev vim wget tightvncserver curl RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev ENV SCRIPTS_DIR=/tmp/scripts diff --git a/builder/dockerfile.fedora_forty.build b/builder/dockerfile.fedora_forty.build index d5ad068..686feb6 100644 --- a/builder/dockerfile.fedora_forty.build +++ b/builder/dockerfile.fedora_forty.build @@ -16,6 +16,7 @@ RUN \ byacc \ bzip2 \ cmake \ + nasm \ diffutils \ doxygen \ file \ diff --git a/builder/dockerfile.fedora_fortyone.build b/builder/dockerfile.fedora_fortyone.build index 5c2bf48..81c44b4 100644 --- a/builder/dockerfile.fedora_fortyone.build +++ b/builder/dockerfile.fedora_fortyone.build @@ -17,6 +17,7 @@ RUN \ byacc \ bzip2 \ cmake \ + nasm \ diffutils \ doxygen \ file \ diff --git a/builder/dockerfile.fedora_thirtynine.build b/builder/dockerfile.fedora_thirtynine.build index 0854956..aa10cf4 100644 --- a/builder/dockerfile.fedora_thirtynine.build +++ b/builder/dockerfile.fedora_thirtynine.build @@ -16,6 +16,7 @@ RUN \ byacc \ bzip2 \ cmake \ + nasm \ diffutils \ doxygen \ file \ diff --git a/builder/dockerfile.kali_kali-rolling.build b/builder/dockerfile.kali_kali-rolling.build index 0812308..43a1e3a 100644 --- a/builder/dockerfile.kali_kali-rolling.build +++ b/builder/dockerfile.kali_kali-rolling.build @@ -13,7 +13,7 @@ RUN apt-get update && \ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev RUN apt-get update && apt-get -y install gcc g++ curl -RUN apt-get update && apt-get -y install cmake git libgnutls28-dev vim wget tightvncserver +RUN apt-get update && apt-get -y install ninja-build cmake nasm git libgnutls28-dev vim wget tightvncserver RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev ENV SCRIPTS_DIR=/tmp/scripts diff --git a/builder/dockerfile.opensuse_15.build b/builder/dockerfile.opensuse_15.build index 800c752..d00eb4b 100644 --- a/builder/dockerfile.opensuse_15.build +++ b/builder/dockerfile.opensuse_15.build @@ -9,6 +9,7 @@ RUN zypper install -ny \ bdftopcf \ bigreqsproto-devel \ cmake \ + nasm \ curl \ ffmpeg-4-libavcodec-devel \ fonttosfnt \ diff --git a/builder/dockerfile.oracle_8.build b/builder/dockerfile.oracle_8.build index f28c1df..59c09f1 100644 --- a/builder/dockerfile.oracle_8.build +++ b/builder/dockerfile.oracle_8.build @@ -12,6 +12,7 @@ RUN \ bzip2-devel \ ca-certificates \ cmake \ + nasm \ dnf-plugins-core \ gcc \ gcc-c++ \ diff --git a/builder/dockerfile.oracle_9.build b/builder/dockerfile.oracle_9.build index ca6e705..fb27999 100644 --- a/builder/dockerfile.oracle_9.build +++ b/builder/dockerfile.oracle_9.build @@ -12,6 +12,7 @@ RUN \ bzip2-devel \ ca-certificates \ cmake \ + nasm \ dnf-plugins-core \ gcc \ gcc-c++ \ diff --git a/builder/dockerfile.ubuntu_focal.build b/builder/dockerfile.ubuntu_focal.build index bdfad4c..03f5253 100644 --- a/builder/dockerfile.ubuntu_focal.build +++ b/builder/dockerfile.ubuntu_focal.build @@ -12,13 +12,11 @@ RUN apt-get update && \ RUN apt-get update && apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev -RUN apt-get update && apt-get -y install cmake git vim wget curl +RUN apt-get update && apt-get -y install ninja-build nasm git vim wget curl RUN apt-get update && apt-get -y install libtbb-dev libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR -RUN $SCRIPTS_DIR/build-webp -RUN $SCRIPTS_DIR/build-libjpeg-turbo RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo @@ -35,6 +33,9 @@ RUN ARCH=$(arch) && \ (echo y; echo n) | bash cmake.sh --prefix=/usr/local --skip-license && \ rm cmake.sh +RUN $SCRIPTS_DIR/build-webp +RUN $SCRIPTS_DIR/build-libjpeg-turbo + COPY --chown=docker:docker . /src/ USER docker diff --git a/builder/dockerfile.ubuntu_jammy.build b/builder/dockerfile.ubuntu_jammy.build index 933fc90..cc6c4ff 100644 --- a/builder/dockerfile.ubuntu_jammy.build +++ b/builder/dockerfile.ubuntu_jammy.build @@ -12,7 +12,7 @@ RUN apt-get update && \ RUN apt-get update && apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev -RUN apt-get update && apt-get -y install cmake git libgnutls28-dev vim wget tightvncserver curl +RUN apt-get update && apt-get -y install ninja-build cmake nasm git libgnutls28-dev vim wget tightvncserver curl RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev ENV SCRIPTS_DIR=/tmp/scripts diff --git a/builder/dockerfile.ubuntu_noble.build b/builder/dockerfile.ubuntu_noble.build index a71ad86..a4c3a6f 100644 --- a/builder/dockerfile.ubuntu_noble.build +++ b/builder/dockerfile.ubuntu_noble.build @@ -12,7 +12,7 @@ RUN apt-get update && \ RUN apt-get update && apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev -RUN apt-get update && apt-get -y install cmake git libgnutls28-dev vim wget curl +RUN apt-get update && apt-get -y install ninja-build cmake nasm git libgnutls28-dev vim wget curl RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev ENV SCRIPTS_DIR=/tmp/scripts From 81fa5f8f653f974c9b89ddff93d97d34aa0d0048 Mon Sep 17 00:00:00 2001 From: El Date: Sun, 16 Mar 2025 17:04:27 +0500 Subject: [PATCH 102/167] KASM-7194 Use `ln -sf` to force symbolic link creation --- builder/build.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/builder/build.sh b/builder/build.sh index be9d899..b35f83d 100755 --- a/builder/build.sh +++ b/builder/build.sh @@ -44,7 +44,10 @@ if [[ "${XORG_VER}" == 21* ]]; then else XORG_PATCH=$(echo "$XORG_VER" | grep -Po '^\d.\d+' | sed 's#\.##') fi -wget --no-check-certificate https://www.x.org/archive/individual/xserver/xorg-server-${XORG_VER}.tar.gz + +if [ ! -f xorg-server-"${XORG_VER}".tar.gz ]; then + wget --no-check-certificate https://www.x.org/archive/individual/xserver/xorg-server-"${XORG_VER}".tar.gz +fi #git clone https://kasmweb@bitbucket.org/kasmtech/kasmvnc.git #cd kasmvnc @@ -59,7 +62,7 @@ sed -i -e '/find_package(FLTK/s@^@#@' \ cmake -D CMAKE_BUILD_TYPE=RelWithDebInfo . -DBUILD_VIEWER:BOOL=OFF \ -DENABLE_GNUTLS:BOOL=OFF -make -j5 +make -j"$(nproc)" tar -C unix/xserver -xf /tmp/xorg-server-${XORG_VER}.tar.gz --strip-components=1 @@ -114,18 +117,22 @@ fi # remove array bounds errors for new versions of GCC find . -name "Makefile" -exec sed -i 's/-Werror=array-bounds//g' {} \; -make -j5 +make -j"$(nproc)" # modifications for the servertarball cd /src mkdir -p xorg.build/bin cd xorg.build/bin/ -ln -s /src/unix/xserver/hw/vnc/Xvnc Xvnc +ln -sf /src/unix/xserver/hw/vnc/Xvnc Xvnc cd .. mkdir -p man/man1 touch man/man1/Xserver.1 cp /src/unix/xserver/hw/vnc/Xvnc.man man/man1/Xvnc.1 -mkdir lib + +if [ ! -d lib ]; then + mkdir lib +fi + cd lib if [ -d /usr/lib/x86_64-linux-gnu/dri ]; then ln -s /usr/lib/x86_64-linux-gnu/dri dri From 35d1d49d208b9ec9dddb8533b76425687acf1250 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 17 Apr 2025 22:34:38 +0500 Subject: [PATCH 103/167] KASM-7194 Add ninja-build and libSM-devel to Docker build files --- builder/dockerfile.opensuse_15.build | 1 + builder/dockerfile.oracle_8.build | 1 + builder/dockerfile.oracle_9.build | 1 + 3 files changed, 3 insertions(+) diff --git a/builder/dockerfile.opensuse_15.build b/builder/dockerfile.opensuse_15.build index d00eb4b..6c2cd1b 100644 --- a/builder/dockerfile.opensuse_15.build +++ b/builder/dockerfile.opensuse_15.build @@ -8,6 +8,7 @@ ENV XORG_VER 1.20.3 RUN zypper install -ny \ bdftopcf \ bigreqsproto-devel \ + ninja \ cmake \ nasm \ curl \ diff --git a/builder/dockerfile.oracle_8.build b/builder/dockerfile.oracle_8.build index 59c09f1..0a9ecfe 100644 --- a/builder/dockerfile.oracle_8.build +++ b/builder/dockerfile.oracle_8.build @@ -11,6 +11,7 @@ RUN \ dnf install -y \ bzip2-devel \ ca-certificates \ + ninja-build \ cmake \ nasm \ dnf-plugins-core \ diff --git a/builder/dockerfile.oracle_9.build b/builder/dockerfile.oracle_9.build index fb27999..aaa9184 100644 --- a/builder/dockerfile.oracle_9.build +++ b/builder/dockerfile.oracle_9.build @@ -11,6 +11,7 @@ RUN \ dnf install -y \ bzip2-devel \ ca-certificates \ + ninja-build \ cmake \ nasm \ dnf-plugins-core \ From cb00ca07c897b5a725b918e434dc654511552154 Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 18 Apr 2025 16:44:46 +0000 Subject: [PATCH 104/167] KASM-7202 run web code from source using node --- BUILDING.txt | 33 +++++++++++++++++++++++ CMakeLists.txt | 2 +- builder/build.sh | 15 ++++++----- builder/conf/nginx_kasm.conf | 42 +++++++++++++++++++++++++++++ builder/dockerfile.ubuntu_jammy.dev | 9 +++++-- 5 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 builder/conf/nginx_kasm.conf diff --git a/BUILDING.txt b/BUILDING.txt index 4bfaa3f..21c33f6 100644 --- a/BUILDING.txt +++ b/BUILDING.txt @@ -105,6 +105,39 @@ Now run Xvnc and Xfce4 from inside the container Now open a browser and navigate to your dev VM on port 6901. +Running noVNC from source +------------------------- +If you need to debug or make changes to the UI code, use the following procedures to use npm to serve the web code. The code will automatically rebuild when changes are made and the code will not be packaged. +These steps assume you have already built the docker image covered in the previous section named `kasmvnc:dev`. + +```bash +# run an instance of the dev container, expose an additional port +sudo docker run -it -v ./:/src -p 6901:6901 -p 8443:8443 --name kasmvnc_dev kasmvnc:dev +``` + +Now from inside the container. **This assumes KasmVNC is already built, follow steps above if you need to build KasmVNC** + +```bash +# Run KasmVNC +/src/xorg.build/bin/Xvnc -interface 0.0.0.0 -PublicIP 127.0.0.1 -disableBasicAuth -RectThreads 0 -Log *:stdout:100 -httpd /src/kasmweb/dist -sslOnly 0 -SecurityTypes None -websocketPort 6901 :1 & +/usr/bin/xfce4-session --display :1 & + +sudo nginx +cd kasmweb +npm install +npm run serve # <-- Needs to run in foreground +``` + +Now open a browser and navigate to your dev VM on port 8443 over https. + +NGINX is proxying the websocket to KasmVNC and all other requests go to the node server. NGINX listens on 8443 with ssl. + +Since `npm run serve` needs to run in the foreground, you may need to exec into the container from another terminal to run additional commands like stopping Xvnc, rebuilding KasmVNC, etc. + +```bash +sudo docker exec -it kasmvnc_dev /bin/bash +``` + Building the KasmVNC Server on Modern Unix/Linux Systems --------------------------------------------------------- diff --git a/CMakeLists.txt b/CMakeLists.txt index 22f21dc..2276b74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,7 +242,7 @@ if(ENABLE_NLS) add_subdirectory(po) endif() -####add_subdirectory(tests) +#############add_subdirectory(tests) include(cmake/BuildPackages.cmake) diff --git a/builder/build.sh b/builder/build.sh index be9d899..2957e64 100755 --- a/builder/build.sh +++ b/builder/build.sh @@ -119,24 +119,25 @@ make -j5 # modifications for the servertarball cd /src mkdir -p xorg.build/bin +mkdir -p xorg.build/lib cd xorg.build/bin/ -ln -s /src/unix/xserver/hw/vnc/Xvnc Xvnc +ln -sf /src/unix/xserver/hw/vnc/Xvnc Xvnc cd .. mkdir -p man/man1 touch man/man1/Xserver.1 cp /src/unix/xserver/hw/vnc/Xvnc.man man/man1/Xvnc.1 -mkdir lib + cd lib if [ -d /usr/lib/x86_64-linux-gnu/dri ]; then - ln -s /usr/lib/x86_64-linux-gnu/dri dri + ln -sfn /usr/lib/x86_64-linux-gnu/dri dri elif [ -d /usr/lib/aarch64-linux-gnu/dri ]; then - ln -s /usr/lib/aarch64-linux-gnu/dri dri + ln -sfn /usr/lib/aarch64-linux-gnu/dri dri elif [ -d /usr/lib/arm-linux-gnueabihf/dri ]; then - ln -s /usr/lib/arm-linux-gnueabihf/dri dri + ln -sfn /usr/lib/arm-linux-gnueabihf/dri dri elif [ -d /usr/lib/xorg/modules/dri ]; then - ln -s /usr/lib/xorg/modules/dri dri + ln -sfn /usr/lib/xorg/modules/dri dri else - ln -s /usr/lib64/dri dri + ln -sfn /usr/lib64/dri dri fi cd /src diff --git a/builder/conf/nginx_kasm.conf b/builder/conf/nginx_kasm.conf new file mode 100644 index 0000000..a341c59 --- /dev/null +++ b/builder/conf/nginx_kasm.conf @@ -0,0 +1,42 @@ +server { + listen 8443 ssl; + ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem; + ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key; + + location / { + proxy_pass http://127.0.0.1:5173; + } + + location /api/ { + proxy_pass https://127.0.0.1:6901; + } + + location /websockify { + # The following configurations must be configured when proxying to Kasm Workspaces + + # WebSocket Support + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + # Host and X headers + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # Connectivity Options + proxy_http_version 1.1; + proxy_read_timeout 1800s; + proxy_send_timeout 1800s; + proxy_connect_timeout 1800s; + proxy_buffering off; + + # Allow large requests to support file uploads to sessions + client_max_body_size 10M; + + # # Proxy to KasmVNC using SSL + #proxy_pass https://127.0.0.1:6901; + # Proxy to KasmVNC without SSL + proxy_pass http://127.0.0.1:6901; + } + } \ No newline at end of file diff --git a/builder/dockerfile.ubuntu_jammy.dev b/builder/dockerfile.ubuntu_jammy.dev index d13638d..803e2a6 100644 --- a/builder/dockerfile.ubuntu_jammy.dev +++ b/builder/dockerfile.ubuntu_jammy.dev @@ -10,13 +10,18 @@ EXPOSE 6901 USER root +COPY builder/conf/nginx_kasm.conf /etc/nginx/conf.d/ + RUN sed -i 's$# deb-src$deb-src$' /etc/apt/sources.list && \ apt update && \ - apt install -y socat sudo libxfont-dev cmake git libgnutls28-dev vim wget tightvncserver curl libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev pkg-config libfreetype6-dev libxtst-dev autoconf automake libtool xutils-dev libpixman-1-dev libxshmfence-dev libxcvt-dev libxkbfile-dev x11proto-dev libgbm-dev inotify-tools && \ + apt install -y socat vim wget tightvncserver curl inotify-tools sudo \ + libxfont-dev libgnutls28-dev libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev pkg-config libfreetype6-dev \ + libxtst-dev xutils-dev libpixman-1-dev libxshmfence-dev libxcvt-dev libxkbfile-dev x11proto-dev libgbm-dev \ + cmake git autoconf automake libtool && \ echo "kasm-user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers RUN curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - -RUN apt install -y nodejs +RUN apt install -y nodejs nginx USER 1000 From 4a4c5f1c499527b23da29c274b62d16b2e7948bb Mon Sep 17 00:00:00 2001 From: El Date: Sat, 19 Apr 2025 00:43:29 +0500 Subject: [PATCH 105/167] KASM-7194 Refactor build scripts and enable conditional test builds --- CMakeLists.txt | 5 +- builder/build.sh | 129 +++++++++++++++++++++++------------------------ 2 files changed, 66 insertions(+), 68 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22f21dc..537063e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,8 +242,9 @@ if(ENABLE_NLS) add_subdirectory(po) endif() -####add_subdirectory(tests) - +if (TESTS) + add_subdirectory(tests) +endif () include(cmake/BuildPackages.cmake) diff --git a/builder/build.sh b/builder/build.sh index b35f83d..ed481df 100755 --- a/builder/build.sh +++ b/builder/build.sh @@ -45,8 +45,10 @@ else XORG_PATCH=$(echo "$XORG_VER" | grep -Po '^\d.\d+' | sed 's#\.##') fi -if [ ! -f xorg-server-"${XORG_VER}".tar.gz ]; then - wget --no-check-certificate https://www.x.org/archive/individual/xserver/xorg-server-"${XORG_VER}".tar.gz +TARBALL="xorg-server-${XORG_VER}.tar.gz" + +if [ ! -f "$TARBALL" ]; then + wget --no-check-certificate https://www.x.org/archive/individual/xserver/"$TARBALL" fi #git clone https://kasmweb@bitbucket.org/kasmtech/kasmvnc.git @@ -54,96 +56,91 @@ fi #git checkout dynjpeg cd /src -# We only want the server, so FLTK and manual tests aren't useful. -# Alternatively, install fltk 1.3 and its dev packages. -sed -i -e '/find_package(FLTK/s@^@#@' \ - -e '/add_subdirectory(tests/s@^@#@' \ - CMakeLists.txt - cmake -D CMAKE_BUILD_TYPE=RelWithDebInfo . -DBUILD_VIEWER:BOOL=OFF \ -DENABLE_GNUTLS:BOOL=OFF make -j"$(nproc)" -tar -C unix/xserver -xf /tmp/xorg-server-${XORG_VER}.tar.gz --strip-components=1 +if [ ! -d unix/xserver/include ]; then + tar -C unix/xserver -xf /tmp/"$TARBALL" --strip-components=1 -cd unix/xserver -# Apply patches -patch -Np1 -i ../xserver${XORG_PATCH}.patch -case "$XORG_VER" in - 1.20.*) - patch -s -p0 < ../CVE-2022-2320-v1.20.patch - if [ -f ../xserver120.7.patch ]; then - patch -Np1 -i ../xserver120.7.patch - fi ;; - 1.19.*) - patch -s -p0 < ../CVE-2022-2320-v1.19.patch - ;; -esac + cd unix/xserver + # Apply patches + patch -Np1 -i ../xserver"${XORG_PATCH}".patch + case "$XORG_VER" in + 1.20.*) + patch -s -p0 < ../CVE-2022-2320-v1.20.patch + if [ -f ../xserver120.7.patch ]; then + patch -Np1 -i ../xserver120.7.patch + fi ;; + 1.19.*) + patch -s -p0 < ../CVE-2022-2320-v1.19.patch + ;; + esac -autoreconf -i -# Configuring Xorg is long and has many distro-specific paths. -# The distro paths start after prefix and end with the font path, -# everything after that is based on BUILDING.txt to remove unneeded -# components. -# remove gl check for opensuse -if [ "${KASMVNC_BUILD_OS}" == "opensuse" ] || ([ "${KASMVNC_BUILD_OS}" == "oracle" ] && [ "${KASMVNC_BUILD_OS_CODENAME}" == 9 ]); then - sed -i 's/LIBGL="gl >= 7.1.0"/LIBGL="gl >= 1.1"/g' configure + autoreconf -i + # Configuring Xorg is long and has many distro-specific paths. + # The distro paths start after prefix and end with the font path, + # everything after that is based on BUILDING.txt to remove unneeded + # components. + # remove gl check for opensuse + if [ "${KASMVNC_BUILD_OS}" == "opensuse" ] || ([ "${KASMVNC_BUILD_OS}" == "oracle" ] && [ "${KASMVNC_BUILD_OS_CODENAME}" == 9 ]); then + sed -i 's/LIBGL="gl >= 7.1.0"/LIBGL="gl >= 1.1"/g' configure + fi + + # build X11 + ./configure \ + --disable-config-hal \ + --disable-config-udev \ + --disable-dmx \ + --disable-dri \ + --disable-dri2 \ + --disable-kdrive \ + --disable-static \ + --disable-xephyr \ + --disable-xinerama \ + --disable-xnest \ + --disable-xorg \ + --disable-xvfb \ + --disable-xwayland \ + --disable-xwin \ + --enable-glx \ + --prefix=/opt/kasmweb \ + --with-default-font-path="/usr/share/fonts/X11/misc,/usr/share/fonts/X11/cyrillic,/usr/share/fonts/X11/100dpi/:unscaled,/usr/share/fonts/X11/75dpi/:unscaled,/usr/share/fonts/X11/Type1,/usr/share/fonts/X11/100dpi,/usr/share/fonts/X11/75dpi,built-ins" \ + --without-dtrace \ + --with-sha1=libcrypto \ + --with-xkb-bin-directory=/usr/bin \ + --with-xkb-output=/var/lib/xkb \ + --with-xkb-path=/usr/share/X11/xkb "${CONFIG_OPTIONS}" + + # remove array bounds errors for new versions of GCC + find . -name "Makefile" -exec sed -i 's/-Werror=array-bounds//g' {} \; fi -# build X11 -./configure \ - --disable-config-hal \ - --disable-config-udev \ - --disable-dmx \ - --disable-dri \ - --disable-dri2 \ - --disable-kdrive \ - --disable-static \ - --disable-xephyr \ - --disable-xinerama \ - --disable-xnest \ - --disable-xorg \ - --disable-xvfb \ - --disable-xwayland \ - --disable-xwin \ - --enable-glx \ - --prefix=/opt/kasmweb \ - --with-default-font-path="/usr/share/fonts/X11/misc,/usr/share/fonts/X11/cyrillic,/usr/share/fonts/X11/100dpi/:unscaled,/usr/share/fonts/X11/75dpi/:unscaled,/usr/share/fonts/X11/Type1,/usr/share/fonts/X11/100dpi,/usr/share/fonts/X11/75dpi,built-ins" \ - --without-dtrace \ - --with-sha1=libcrypto \ - --with-xkb-bin-directory=/usr/bin \ - --with-xkb-output=/var/lib/xkb \ - --with-xkb-path=/usr/share/X11/xkb ${CONFIG_OPTIONS} - -# remove array bounds errors for new versions of GCC -find . -name "Makefile" -exec sed -i 's/-Werror=array-bounds//g' {} \; make -j"$(nproc)" # modifications for the servertarball cd /src mkdir -p xorg.build/bin cd xorg.build/bin/ -ln -sf /src/unix/xserver/hw/vnc/Xvnc Xvnc +ln -sfn /src/unix/xserver/hw/vnc/Xvnc Xvnc cd .. mkdir -p man/man1 touch man/man1/Xserver.1 cp /src/unix/xserver/hw/vnc/Xvnc.man man/man1/Xvnc.1 -if [ ! -d lib ]; then - mkdir lib -fi +mkdir -p lib cd lib if [ -d /usr/lib/x86_64-linux-gnu/dri ]; then - ln -s /usr/lib/x86_64-linux-gnu/dri dri + ln -sfn /usr/lib/x86_64-linux-gnu/dri dri elif [ -d /usr/lib/aarch64-linux-gnu/dri ]; then - ln -s /usr/lib/aarch64-linux-gnu/dri dri + ln -sfn /usr/lib/aarch64-linux-gnu/dri dri elif [ -d /usr/lib/arm-linux-gnueabihf/dri ]; then - ln -s /usr/lib/arm-linux-gnueabihf/dri dri + ln -sfn /usr/lib/arm-linux-gnueabihf/dri dri elif [ -d /usr/lib/xorg/modules/dri ]; then - ln -s /usr/lib/xorg/modules/dri dri + ln -sfn /usr/lib/xorg/modules/dri dri else - ln -s /usr/lib64/dri dri + ln -sfn /usr/lib64/dri dri fi cd /src From 60f015b1997f3ff8eb1ed29739342b74fa430d7a Mon Sep 17 00:00:00 2001 From: Rodwin Spruel Date: Tue, 22 Apr 2025 11:22:20 +0000 Subject: [PATCH 106/167] Adding ability to override webp benchmark value --- common/rfb/EncodeManager.cxx | 2 +- common/rfb/ServerCore.cxx | 5 +++++ common/rfb/ServerCore.h | 1 + common/rfb/TightWEBPEncoder.cxx | 5 +++-- unix/vncserver | 9 +++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index 5e94cdc..30bfdce 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -395,7 +395,7 @@ void EncodeManager::doUpdate(bool allowLossy, const Region& changed_, screenArea = pb->getRect().width() * pb->getRect().height(); screenArea *= 1024; screenArea /= 256 * 256; - screenArea *= webpBenchResult; + screenArea *= screenArea *= Server::webpEncodingTime > 0 ? Server::webpEncodingTime : webpBenchResult; // Encoding the entire screen would take this many 1024*msecs, worst case // Calculate how many us we can send webp for, before switching to jpeg diff --git a/common/rfb/ServerCore.cxx b/common/rfb/ServerCore.cxx index 03a69d9..3c15be6 100644 --- a/common/rfb/ServerCore.cxx +++ b/common/rfb/ServerCore.cxx @@ -287,3 +287,8 @@ rfb::PresetParameter rfb::Server::preferBandwidth ("PreferBandwidth", "Set various options for lower bandwidth use. The default is off, aka to prefer quality.", false, bandwidthPreset); + +rfb::IntParameter rfb::Server::webpEncodingTime +("udpPort", + "Sets the benchmak WebP encoding time in KasmVNC. Default is calculated in TightWEBPEncoder benchmark function", + 0, 0, 10000); diff --git a/common/rfb/ServerCore.h b/common/rfb/ServerCore.h index 2035cf6..c3a53e5 100644 --- a/common/rfb/ServerCore.h +++ b/common/rfb/ServerCore.h @@ -91,6 +91,7 @@ namespace rfb { static BoolParameter ignoreClientSettingsKasm; static BoolParameter selfBench; static PresetParameter preferBandwidth; + static IntParameter webpEncodingTime; }; }; diff --git a/common/rfb/TightWEBPEncoder.cxx b/common/rfb/TightWEBPEncoder.cxx index 89d9b3a..2e79c6c 100644 --- a/common/rfb/TightWEBPEncoder.cxx +++ b/common/rfb/TightWEBPEncoder.cxx @@ -259,13 +259,14 @@ void TightWEBPEncoder::writeRect(const PixelBuffer* pb, const Palette& palette) WebPMemoryWriterClear(&wrt); } -// How many milliseconds would it take to encode a 256x256 block at quality 8 +// How many milliseconds would it take to encode a 256x256 block at quality 5 rdr::U32 TightWEBPEncoder::benchmark() const { rdr::U8* buffer; struct timeval start; int stride, i; - const uint8_t quality = 8, method = 2; + // the minimum WebP quality settings used in KasmVNC + const uint8_t quality = 5, method = 0; WebPConfig cfg; WebPPicture pic; WebPMemoryWriter wrt; diff --git a/unix/vncserver b/unix/vncserver index 41fc1be..eb2695f 100755 --- a/unix/vncserver +++ b/unix/vncserver @@ -2068,6 +2068,15 @@ sub DefineConfigToCLIConversion { $value; } }), + KasmVNC::CliOption->new({ + name => 'webpEncodingTime', + configKeys => [ + KasmVNC::ConfigKey->new({ + name => "encoding.video_encoding_mode.webp_encoding_time", + type => KasmVNC::ConfigKey::INT + }) + ] + }), KasmVNC::CliOption->new({ name => 'CompareFB', configKeys => [ From 2dbcd283545921d4c9a53196e0bd461d2d2fd25d Mon Sep 17 00:00:00 2001 From: Rodwin Spruel Date: Tue, 22 Apr 2025 11:22:20 +0000 Subject: [PATCH 107/167] Adding ability to override webp benchmark value --- common/rfb/EncodeManager.cxx | 2 +- common/rfb/ServerCore.cxx | 5 +++++ common/rfb/ServerCore.h | 1 + common/rfb/TightWEBPEncoder.cxx | 5 +++-- unix/vncserver | 9 +++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index 5e94cdc..30bfdce 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -395,7 +395,7 @@ void EncodeManager::doUpdate(bool allowLossy, const Region& changed_, screenArea = pb->getRect().width() * pb->getRect().height(); screenArea *= 1024; screenArea /= 256 * 256; - screenArea *= webpBenchResult; + screenArea *= screenArea *= Server::webpEncodingTime > 0 ? Server::webpEncodingTime : webpBenchResult; // Encoding the entire screen would take this many 1024*msecs, worst case // Calculate how many us we can send webp for, before switching to jpeg diff --git a/common/rfb/ServerCore.cxx b/common/rfb/ServerCore.cxx index 03a69d9..3c15be6 100644 --- a/common/rfb/ServerCore.cxx +++ b/common/rfb/ServerCore.cxx @@ -287,3 +287,8 @@ rfb::PresetParameter rfb::Server::preferBandwidth ("PreferBandwidth", "Set various options for lower bandwidth use. The default is off, aka to prefer quality.", false, bandwidthPreset); + +rfb::IntParameter rfb::Server::webpEncodingTime +("udpPort", + "Sets the benchmak WebP encoding time in KasmVNC. Default is calculated in TightWEBPEncoder benchmark function", + 0, 0, 10000); diff --git a/common/rfb/ServerCore.h b/common/rfb/ServerCore.h index 2035cf6..c3a53e5 100644 --- a/common/rfb/ServerCore.h +++ b/common/rfb/ServerCore.h @@ -91,6 +91,7 @@ namespace rfb { static BoolParameter ignoreClientSettingsKasm; static BoolParameter selfBench; static PresetParameter preferBandwidth; + static IntParameter webpEncodingTime; }; }; diff --git a/common/rfb/TightWEBPEncoder.cxx b/common/rfb/TightWEBPEncoder.cxx index 89d9b3a..2e79c6c 100644 --- a/common/rfb/TightWEBPEncoder.cxx +++ b/common/rfb/TightWEBPEncoder.cxx @@ -259,13 +259,14 @@ void TightWEBPEncoder::writeRect(const PixelBuffer* pb, const Palette& palette) WebPMemoryWriterClear(&wrt); } -// How many milliseconds would it take to encode a 256x256 block at quality 8 +// How many milliseconds would it take to encode a 256x256 block at quality 5 rdr::U32 TightWEBPEncoder::benchmark() const { rdr::U8* buffer; struct timeval start; int stride, i; - const uint8_t quality = 8, method = 2; + // the minimum WebP quality settings used in KasmVNC + const uint8_t quality = 5, method = 0; WebPConfig cfg; WebPPicture pic; WebPMemoryWriter wrt; diff --git a/unix/vncserver b/unix/vncserver index 41fc1be..eb2695f 100755 --- a/unix/vncserver +++ b/unix/vncserver @@ -2068,6 +2068,15 @@ sub DefineConfigToCLIConversion { $value; } }), + KasmVNC::CliOption->new({ + name => 'webpEncodingTime', + configKeys => [ + KasmVNC::ConfigKey->new({ + name => "encoding.video_encoding_mode.webp_encoding_time", + type => KasmVNC::ConfigKey::INT + }) + ] + }), KasmVNC::CliOption->new({ name => 'CompareFB', configKeys => [ From 7353f386524c4ee6baf7ecb558322a65375e04e1 Mon Sep 17 00:00:00 2001 From: "Rodwin.Spruel" Date: Tue, 22 Apr 2025 10:39:53 -0400 Subject: [PATCH 108/167] Adding defaults and fixing typo --- common/rfb/ServerCore.cxx | 4 ++-- unix/kasmvnc_defaults.yaml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/common/rfb/ServerCore.cxx b/common/rfb/ServerCore.cxx index 3c15be6..f242b54 100644 --- a/common/rfb/ServerCore.cxx +++ b/common/rfb/ServerCore.cxx @@ -289,6 +289,6 @@ rfb::PresetParameter rfb::Server::preferBandwidth false, bandwidthPreset); rfb::IntParameter rfb::Server::webpEncodingTime -("udpPort", - "Sets the benchmak WebP encoding time in KasmVNC. Default is calculated in TightWEBPEncoder benchmark function", +("webpEncodingTime", + "Sets a weighted value that determines how much webp is used to balance bandwidth and CPU usage.", 0, 0, 10000); diff --git a/unix/kasmvnc_defaults.yaml b/unix/kasmvnc_defaults.yaml index 3d0551c..e75591e 100644 --- a/unix/kasmvnc_defaults.yaml +++ b/unix/kasmvnc_defaults.yaml @@ -129,6 +129,7 @@ encoding: logging: level: off scaling_algorithm: progressive_bilinear + webp_encoding_time: 0 compare_framebuffer: auto zrle_zlib_level: auto From 3bc040387767544dc3932aba1e50a7e07a1477a6 Mon Sep 17 00:00:00 2001 From: "Rodwin.Spruel" Date: Tue, 22 Apr 2025 17:17:58 -0400 Subject: [PATCH 109/167] Updating weighting function and limits Signed-off-by: Rodwin.Spruel --- common/rfb/EncodeManager.cxx | 3 ++- common/rfb/ServerCore.cxx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index 30bfdce..69142c0 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -395,7 +395,8 @@ void EncodeManager::doUpdate(bool allowLossy, const Region& changed_, screenArea = pb->getRect().width() * pb->getRect().height(); screenArea *= 1024; screenArea /= 256 * 256; - screenArea *= screenArea *= Server::webpEncodingTime > 0 ? Server::webpEncodingTime : webpBenchResult; + screenArea *= screenArea; + screenArea /= Server::webpEncodingTime > 1 ? Server::webpEncodingTime : 1; // Encoding the entire screen would take this many 1024*msecs, worst case // Calculate how many us we can send webp for, before switching to jpeg diff --git a/common/rfb/ServerCore.cxx b/common/rfb/ServerCore.cxx index f242b54..91174d6 100644 --- a/common/rfb/ServerCore.cxx +++ b/common/rfb/ServerCore.cxx @@ -291,4 +291,4 @@ rfb::PresetParameter rfb::Server::preferBandwidth rfb::IntParameter rfb::Server::webpEncodingTime ("webpEncodingTime", "Sets a weighted value that determines how much webp is used to balance bandwidth and CPU usage.", - 0, 0, 10000); + 1, 1, 1000); From f674e2c58df88038dab84f01baa4b7498e681b19 Mon Sep 17 00:00:00 2001 From: Rodwin Spruel Date: Tue, 22 Apr 2025 21:45:16 +0000 Subject: [PATCH 110/167] Fixing default value --- unix/kasmvnc_defaults.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unix/kasmvnc_defaults.yaml b/unix/kasmvnc_defaults.yaml index e75591e..c4e2a03 100644 --- a/unix/kasmvnc_defaults.yaml +++ b/unix/kasmvnc_defaults.yaml @@ -129,7 +129,7 @@ encoding: logging: level: off scaling_algorithm: progressive_bilinear - webp_encoding_time: 0 + webp_encoding_time: 1 compare_framebuffer: auto zrle_zlib_level: auto From 02852185a86475737bb047a3abbd099a9274af08 Mon Sep 17 00:00:00 2001 From: "Rodwin.Spruel" Date: Thu, 24 Apr 2025 05:57:25 -0400 Subject: [PATCH 111/167] Fixing webp usage calculation and updating default value --- common/rfb/EncodeManager.cxx | 4 ++-- unix/kasmvnc_defaults.yaml | 24 ++++++++++++------------ unix/vncserver | 18 +++++++++++++++--- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index 69142c0..cd855e9 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -395,8 +395,8 @@ void EncodeManager::doUpdate(bool allowLossy, const Region& changed_, screenArea = pb->getRect().width() * pb->getRect().height(); screenArea *= 1024; screenArea /= 256 * 256; - screenArea *= screenArea; - screenArea /= Server::webpEncodingTime > 1 ? Server::webpEncodingTime : 1; + screenArea *= webpBenchResult; + screenArea /= Server::webpEncodingTime; // Encoding the entire screen would take this many 1024*msecs, worst case // Calculate how many us we can send webp for, before switching to jpeg diff --git a/unix/kasmvnc_defaults.yaml b/unix/kasmvnc_defaults.yaml index c4e2a03..1f042ee 100644 --- a/unix/kasmvnc_defaults.yaml +++ b/unix/kasmvnc_defaults.yaml @@ -37,7 +37,7 @@ user_session: keyboard: remap_keys: - # - 0x22->0x40 + # - 0x22->0x40 ignore_numlock: false raw_keyboard: false @@ -92,16 +92,16 @@ data_loss_prevention: enabled: true rate_limit: unlimited watermark: - # image: /etc/kasmvnc/picture.png - # location: 10,10 - # tint: 255,20,20,128 - # repeat_spacing: 10 - #text: - # template: "${USER} %H:%M" - # font: auto - # font_size: 48 - # timezone_name: Australia/Adelaide - # angle: 0 + # image: /etc/kasmvnc/picture.png + # location: 10,10 + # tint: 255,20,20,128 + # repeat_spacing: 10 + #text: + # template: "${USER} %H:%M" + # font: auto + # font_size: 48 + # timezone_name: Australia/Adelaide + # angle: 0 logging: # "verbose" SETTING LOGS YOUR PRIVATE INFORMATION. Keypresses and clipboard content level: off @@ -129,7 +129,7 @@ encoding: logging: level: off scaling_algorithm: progressive_bilinear - webp_encoding_time: 1 + webp_encoding_time: auto compare_framebuffer: auto zrle_zlib_level: auto diff --git a/unix/vncserver b/unix/vncserver index eb2695f..975d4a9 100755 --- a/unix/vncserver +++ b/unix/vncserver @@ -2069,13 +2069,25 @@ sub DefineConfigToCLIConversion { } }), KasmVNC::CliOption->new({ - name => 'webpEncodingTime', + name => 'WebpEncodingTime', configKeys => [ KasmVNC::ConfigKey->new({ name => "encoding.video_encoding_mode.webp_encoding_time", - type => KasmVNC::ConfigKey::INT + validator => KasmVNC::PatternValidator->new({ + pattern => qr/^(auto|[1-9][0-9]{0,2}|1000)$/, + errorMessage => "must be 'auto' or a number in 1..1000" + }), }) - ] + ], + deriveValueSub => sub { + my $self = shift; + my $value = $self->configValue(); + + if ($value eq "auto") { + $value = 1; + } + $value; + } }), KasmVNC::CliOption->new({ name => 'CompareFB', From 00b8d025db7ab77471e29652c2f0d7bb22a144f7 Mon Sep 17 00:00:00 2001 From: matt Date: Thu, 24 Apr 2025 16:50:44 +0000 Subject: [PATCH 112/167] KASM-7125 fixed issue with rebuilding Xvnc, switched to simplier webp mix math. --- builder/build.sh | 79 +++++++++++++++++++----------------- common/rfb/EncodeManager.cxx | 15 +------ common/rfb/ServerCore.cxx | 4 +- unix/kasmvnc_defaults.yaml | 22 +++++----- unix/vncserver | 30 ++++---------- 5 files changed, 65 insertions(+), 85 deletions(-) diff --git a/builder/build.sh b/builder/build.sh index ed481df..332fd27 100755 --- a/builder/build.sh +++ b/builder/build.sh @@ -76,46 +76,49 @@ if [ ! -d unix/xserver/include ]; then patch -s -p0 < ../CVE-2022-2320-v1.19.patch ;; esac - - autoreconf -i - # Configuring Xorg is long and has many distro-specific paths. - # The distro paths start after prefix and end with the font path, - # everything after that is based on BUILDING.txt to remove unneeded - # components. - # remove gl check for opensuse - if [ "${KASMVNC_BUILD_OS}" == "opensuse" ] || ([ "${KASMVNC_BUILD_OS}" == "oracle" ] && [ "${KASMVNC_BUILD_OS_CODENAME}" == 9 ]); then - sed -i 's/LIBGL="gl >= 7.1.0"/LIBGL="gl >= 1.1"/g' configure - fi - - # build X11 - ./configure \ - --disable-config-hal \ - --disable-config-udev \ - --disable-dmx \ - --disable-dri \ - --disable-dri2 \ - --disable-kdrive \ - --disable-static \ - --disable-xephyr \ - --disable-xinerama \ - --disable-xnest \ - --disable-xorg \ - --disable-xvfb \ - --disable-xwayland \ - --disable-xwin \ - --enable-glx \ - --prefix=/opt/kasmweb \ - --with-default-font-path="/usr/share/fonts/X11/misc,/usr/share/fonts/X11/cyrillic,/usr/share/fonts/X11/100dpi/:unscaled,/usr/share/fonts/X11/75dpi/:unscaled,/usr/share/fonts/X11/Type1,/usr/share/fonts/X11/100dpi,/usr/share/fonts/X11/75dpi,built-ins" \ - --without-dtrace \ - --with-sha1=libcrypto \ - --with-xkb-bin-directory=/usr/bin \ - --with-xkb-output=/var/lib/xkb \ - --with-xkb-path=/usr/share/X11/xkb "${CONFIG_OPTIONS}" - - # remove array bounds errors for new versions of GCC - find . -name "Makefile" -exec sed -i 's/-Werror=array-bounds//g' {} \; +else + cd unix/xserver fi +autoreconf -i +# Configuring Xorg is long and has many distro-specific paths. +# The distro paths start after prefix and end with the font path, +# everything after that is based on BUILDING.txt to remove unneeded +# components. +# remove gl check for opensuse +if [ "${KASMVNC_BUILD_OS}" == "opensuse" ] || ([ "${KASMVNC_BUILD_OS}" == "oracle" ] && [ "${KASMVNC_BUILD_OS_CODENAME}" == 9 ]); then + sed -i 's/LIBGL="gl >= 7.1.0"/LIBGL="gl >= 1.1"/g' configure +fi + +# build X11 +./configure \ + --disable-config-hal \ + --disable-config-udev \ + --disable-dmx \ + --disable-dri \ + --disable-dri2 \ + --disable-kdrive \ + --disable-static \ + --disable-xephyr \ + --disable-xinerama \ + --disable-xnest \ + --disable-xorg \ + --disable-xvfb \ + --disable-xwayland \ + --disable-xwin \ + --enable-glx \ + --prefix=/opt/kasmweb \ + --with-default-font-path="/usr/share/fonts/X11/misc,/usr/share/fonts/X11/cyrillic,/usr/share/fonts/X11/100dpi/:unscaled,/usr/share/fonts/X11/75dpi/:unscaled,/usr/share/fonts/X11/Type1,/usr/share/fonts/X11/100dpi,/usr/share/fonts/X11/75dpi,built-ins" \ + --without-dtrace \ + --with-sha1=libcrypto \ + --with-xkb-bin-directory=/usr/bin \ + --with-xkb-output=/var/lib/xkb \ + --with-xkb-path=/usr/share/X11/xkb "${CONFIG_OPTIONS}" + +# remove array bounds errors for new versions of GCC +find . -name "Makefile" -exec sed -i 's/-Werror=array-bounds//g' {} \; + + make -j"$(nproc)" # modifications for the servertarball diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index cd855e9..5dbf1dc 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -360,7 +360,6 @@ void EncodeManager::doUpdate(bool allowLossy, const Region& changed_, int nRects; Region changed, cursorRegion; struct timeval start; - unsigned screenArea; updates++; if (conn->cp.supportsUdp) @@ -390,17 +389,7 @@ void EncodeManager::doUpdate(bool allowLossy, const Region& changed_, memset(&webpstats, 0, sizeof(codecstats_t)); if (allowLossy && activeEncoders[encoderFullColour] == encoderTightWEBP) { - const unsigned rate = 1024 * 1000 / rfb::Server::frameRate; - - screenArea = pb->getRect().width() * pb->getRect().height(); - screenArea *= 1024; - screenArea /= 256 * 256; - screenArea *= webpBenchResult; - screenArea /= Server::webpEncodingTime; - // Encoding the entire screen would take this many 1024*msecs, worst case - - // Calculate how many us we can send webp for, before switching to jpeg - webpFallbackUs = rate * rate / screenArea; + webpFallbackUs = (1000 * 1000 / rfb::Server::frameRate) * (static_cast(Server::webpEncodingTime) / 100.0); } /* @@ -884,7 +873,7 @@ void EncodeManager::findSolidRect(const Rect& rect, Region *changed, void EncodeManager::checkWebpFallback(const timeval *start) { // Have we taken too long for the frame? If so, drop from WEBP to JPEG if (start && activeEncoders[encoderFullColour] == encoderTightWEBP && !webpTookTooLong.load(std::memory_order_relaxed)) { - const auto us = msSince(start) * 1024; + const auto us = msSince(start) * 1000; if (us > webpFallbackUs) webpTookTooLong.store(true, std::memory_order_relaxed); } diff --git a/common/rfb/ServerCore.cxx b/common/rfb/ServerCore.cxx index 91174d6..3881693 100644 --- a/common/rfb/ServerCore.cxx +++ b/common/rfb/ServerCore.cxx @@ -290,5 +290,5 @@ rfb::PresetParameter rfb::Server::preferBandwidth rfb::IntParameter rfb::Server::webpEncodingTime ("webpEncodingTime", - "Sets a weighted value that determines how much webp is used to balance bandwidth and CPU usage.", - 1, 1, 1000); + "Percentage of time allotted for encoding a frame, that can be used for encoding rects in webp.", + 30, 0, 100); diff --git a/unix/kasmvnc_defaults.yaml b/unix/kasmvnc_defaults.yaml index 1f042ee..afad666 100644 --- a/unix/kasmvnc_defaults.yaml +++ b/unix/kasmvnc_defaults.yaml @@ -92,16 +92,16 @@ data_loss_prevention: enabled: true rate_limit: unlimited watermark: - # image: /etc/kasmvnc/picture.png - # location: 10,10 - # tint: 255,20,20,128 - # repeat_spacing: 10 - #text: - # template: "${USER} %H:%M" - # font: auto - # font_size: 48 - # timezone_name: Australia/Adelaide - # angle: 0 + # image: /etc/kasmvnc/picture.png + # location: 10,10 + # tint: 255,20,20,128 + # repeat_spacing: 10 + #text: + # template: "${USER} %H:%M" + # font: auto + # font_size: 48 + # timezone_name: Australia/Adelaide + # angle: 0 logging: # "verbose" SETTING LOGS YOUR PRIVATE INFORMATION. Keypresses and clipboard content level: off @@ -129,7 +129,7 @@ encoding: logging: level: off scaling_algorithm: progressive_bilinear - webp_encoding_time: auto + webp_encoding_time: 30 compare_framebuffer: auto zrle_zlib_level: auto diff --git a/unix/vncserver b/unix/vncserver index 975d4a9..1ac99c8 100755 --- a/unix/vncserver +++ b/unix/vncserver @@ -2068,27 +2068,15 @@ sub DefineConfigToCLIConversion { $value; } }), - KasmVNC::CliOption->new({ - name => 'WebpEncodingTime', - configKeys => [ - KasmVNC::ConfigKey->new({ - name => "encoding.video_encoding_mode.webp_encoding_time", - validator => KasmVNC::PatternValidator->new({ - pattern => qr/^(auto|[1-9][0-9]{0,2}|1000)$/, - errorMessage => "must be 'auto' or a number in 1..1000" - }), - }) - ], - deriveValueSub => sub { - my $self = shift; - my $value = $self->configValue(); - - if ($value eq "auto") { - $value = 1; - } - $value; - } - }), + KasmVNC::CliOption->new({ + name => 'WebpEncodingTime', + configKeys => [ + KasmVNC::ConfigKey->new({ + name => "encoding.video_encoding_mode.webp_encoding_time", + type => KasmVNC::ConfigKey::INT + }) + ] + }), KasmVNC::CliOption->new({ name => 'CompareFB', configKeys => [ From 49906f1d6bcd926ed08e3ccc74d9307553145925 Mon Sep 17 00:00:00 2001 From: El Date: Fri, 28 Mar 2025 15:59:07 +0500 Subject: [PATCH 113/167] KASM-6984 Add `elapsedMs` function for time measurement in milliseconds using modern C++ --- common/rfb/util.cxx | 9 +++++++-- common/rfb/util.h | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/common/rfb/util.cxx b/common/rfb/util.cxx index 649eb0b..a0f5cac 100644 --- a/common/rfb/util.cxx +++ b/common/rfb/util.cxx @@ -21,8 +21,8 @@ #include #endif -#include -#include +#include +#include #include #include @@ -572,6 +572,11 @@ namespace rfb { return msBetween(then, &now); } + uint64_t elapsedMs(std::chrono::high_resolution_clock::time_point start) + { + return std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - start).count(); + } + bool isBefore(const struct timeval *first, const struct timeval *second) { diff --git a/common/rfb/util.h b/common/rfb/util.h index 3100f90..18d38ac 100644 --- a/common/rfb/util.h +++ b/common/rfb/util.h @@ -28,8 +28,9 @@ #include #endif -#include -#include +#include +#include +#include struct timeval; @@ -127,6 +128,15 @@ namespace rfb { // Returns time elapsed since given moment in milliseconds. unsigned msSince(const struct timeval *then); + /** + * Calculates the number of milliseconds elapsed since a given starting point. + * + * @param start The starting time point of type `std::chrono::high_resolution_clock::time_point`. + * + * @return The elapsed time in milliseconds as an unsigned 64-bit integer. + */ + uint64_t elapsedMs(std::chrono::high_resolution_clock::time_point start); + // Returns true if first happened before seconds bool isBefore(const struct timeval *first, const struct timeval *second); From f6c0fa9a53164fbf11d29165f6330018861eb4c2 Mon Sep 17 00:00:00 2001 From: El Date: Fri, 28 Mar 2025 16:01:11 +0500 Subject: [PATCH 114/167] KASM-6984 Replaced macros with constexpr for readability and type safety. Introduced a generalized benchmarking template for reuse and cleaned up repetitive code. Added XML output for test results using TinyXML2 to improve reporting and analysis. --- common/rfb/SelfBench.cxx | 182 +++++++++++++++++++-------------------- 1 file changed, 89 insertions(+), 93 deletions(-) diff --git a/common/rfb/SelfBench.cxx b/common/rfb/SelfBench.cxx index fd224d3..550d6dd 100644 --- a/common/rfb/SelfBench.cxx +++ b/common/rfb/SelfBench.cxx @@ -26,27 +26,42 @@ #include #include #include -#include -#include +#include +#include +#include +#include using namespace rfb; static LogWriter vlog("SelfBench"); static const PixelFormat pfRGBX(32, 24, false, true, 255, 255, 255, 0, 8, 16); -#define RUNS 64 +static constexpr uint32_t RUNS = 64; -#define W 1600 -#define H 1200 +static constexpr uint32_t WIDTH = 1600; +static constexpr uint32_t HEIGHT = 1200; + +template +constexpr bool has_no_args = std::is_invocable_v; + +template +constexpr bool has_one_arg = std::is_invocable_v; void SelfBench() { + tinyxml2::XMLDocument doc; - unsigned i, runs; - struct timeval start; + auto *root = doc.NewElement("testsuites"); + root->SetAttribute("name", "Benchmarking"); - ManagedPixelBuffer f1(pfRGBX, W, H); - ManagedPixelBuffer f2(pfRGBX, W, H); - ManagedPixelBuffer screen(pfRGBX, W, H); + auto *test_suits = doc.InsertFirstChild(root); + + auto *test_suit = doc.NewElement("testsuit"); + test_suit->SetAttribute("name", "SelfBench"); + test_suits->InsertEndChild(test_suit); + + ManagedPixelBuffer f1(pfRGBX, WIDTH, HEIGHT); + ManagedPixelBuffer f2(pfRGBX, WIDTH, HEIGHT); + ManagedPixelBuffer screen(pfRGBX, WIDTH, HEIGHT); int stride; rdr::U8 *f1ptr = f1.getBufferRW(f1.getRect(), &stride); @@ -56,7 +71,7 @@ void SelfBench() { rdr::U8 * const f1orig = f1ptr; rdr::U8 * const f2orig = f2ptr; - for (i = 0; i < W * H * 4; i += 4) { + for (uint32_t i = 0; i < WIDTH * HEIGHT * 4; i += 4) { f1ptr[0] = rand(); f1ptr[1] = rand(); f1ptr[2] = rand(); @@ -74,124 +89,105 @@ void SelfBench() { // Encoding std::vector vec; - TightJPEGEncoder jpeg(NULL); + TightJPEGEncoder jpeg(nullptr); - gettimeofday(&start, NULL); - runs = RUNS; - for (i = 0; i < runs; i++) { + auto benchmark = [&doc, &test_suit](const char *name, uint32_t runs, auto func) { + auto now = std::chrono::high_resolution_clock::now(); + for (uint32_t i = 0; i < runs; i++) { + func(i); + } + + auto value = elapsedMs(now); + vlog.info("%s took %lu ms (%u runs)", name, value, RUNS); + auto *test_case = doc.NewElement("testcase"); + test_case->SetAttribute("name", name); + test_case->SetAttribute("time", value); + test_case->SetAttribute("runs", RUNS); + test_suit->InsertEndChild(test_case); + }; + + benchmark("Jpeg compression at quality 8", RUNS, [&jpeg, &vec, &f1](uint32_t) { jpeg.compressOnly(&f1, 8, vec, false); - } - vlog.info("Jpeg compression at quality 8 took %u ms (%u runs)", msSince(&start), runs); + }); - gettimeofday(&start, NULL); - runs = RUNS; - for (i = 0; i < runs; i++) { + benchmark("Jpeg compression at quality 4", RUNS, [&jpeg, &vec, &f1](uint32_t) { jpeg.compressOnly(&f1, 4, vec, false); - } - vlog.info("Jpeg compression at quality 4 took %u ms (%u runs)", msSince(&start), runs); + }); + TightWEBPEncoder webp(nullptr); - TightWEBPEncoder webp(NULL); - - gettimeofday(&start, NULL); - runs = RUNS / 8; - for (i = 0; i < runs; i++) { + benchmark("Webp compression at quality 8", RUNS / 8, [&webp,&f1, &vec](uint32_t) { webp.compressOnly(&f1, 8, vec, false); - } - vlog.info("Webp compression at quality 8 took %u ms (%u runs)", msSince(&start), runs); + }); - gettimeofday(&start, NULL); - runs = RUNS / 4; - for (i = 0; i < runs; i++) { + benchmark("Webp compression at quality 4", RUNS / 4, [&webp, &f1, &vec](uint32_t) { webp.compressOnly(&f1, 4, vec, false); - } - vlog.info("Webp compression at quality 4 took %u ms (%u runs)", msSince(&start), runs); + }); // Scaling - gettimeofday(&start, NULL); - runs = RUNS; - for (i = 0; i < runs; i++) { - PixelBuffer *pb = nearestScale(&f1, W * 0.8, H * 0.8, 0.8); + benchmark("Nearest scaling to 80%", RUNS, [&f1](uint32_t) { + PixelBuffer *pb = nearestScale(&f1, WIDTH * 0.8, HEIGHT * 0.8, 0.8); delete pb; - } - vlog.info("Nearest scaling to 80%% took %u ms (%u runs)", msSince(&start), runs); + }); - gettimeofday(&start, NULL); - runs = RUNS; - for (i = 0; i < runs; i++) { - PixelBuffer *pb = nearestScale(&f1, W * 0.4, H * 0.4, 0.4); + benchmark("Nearest scaling to 40%", RUNS, [&f1](uint32_t) { + PixelBuffer *pb = nearestScale(&f1, WIDTH * 0.4, HEIGHT * 0.4, 0.4); delete pb; - } - vlog.info("Nearest scaling to 40%% took %u ms (%u runs)", msSince(&start), runs); + }); - gettimeofday(&start, NULL); - runs = RUNS; - for (i = 0; i < runs; i++) { - PixelBuffer *pb = bilinearScale(&f1, W * 0.8, H * 0.8, 0.8); + benchmark("Bilinear scaling to 80%", RUNS, [&f1](uint32_t) { + PixelBuffer *pb = bilinearScale(&f1, WIDTH * 0.8, HEIGHT * 0.8, 0.8); delete pb; - } - vlog.info("Bilinear scaling to 80%% took %u ms (%u runs)", msSince(&start), runs); + }); - gettimeofday(&start, NULL); - runs = RUNS; - for (i = 0; i < runs; i++) { - PixelBuffer *pb = bilinearScale(&f1, W * 0.4, H * 0.4, 0.4); + benchmark("Bilinear scaling to 40%", RUNS, [&f1](uint32_t) { + PixelBuffer *pb = bilinearScale(&f1, WIDTH * 0.4, HEIGHT * 0.4, 0.4); delete pb; - } - vlog.info("Bilinear scaling to 40%% took %u ms (%u runs)", msSince(&start), runs); + }); - gettimeofday(&start, NULL); - runs = RUNS; - for (i = 0; i < runs; i++) { - PixelBuffer *pb = progressiveBilinearScale(&f1, W * 0.8, H * 0.8, 0.8); - delete pb; - } - vlog.info("Progressive bilinear scaling to 80%% took %u ms (%u runs)", msSince(&start), runs); - gettimeofday(&start, NULL); - runs = RUNS; - for (i = 0; i < runs; i++) { - PixelBuffer *pb = progressiveBilinearScale(&f1, W * 0.4, H * 0.4, 0.4); + benchmark("Progressive bilinear scaling to 80%", RUNS, [&f1](uint32_t) { + PixelBuffer *pb = progressiveBilinearScale(&f1, WIDTH * 0.8, HEIGHT * 0.8, 0.8); delete pb; - } - vlog.info("Progressive bilinear scaling to 40%% took %u ms (%u runs)", msSince(&start), runs); + }); + benchmark("Progressive bilinear scaling to 40%", RUNS, [&f1](uint32_t) { + PixelBuffer *pb = progressiveBilinearScale(&f1, WIDTH * 0.4, HEIGHT * 0.4, 0.4); + delete pb; + }); // Analysis - ComparingUpdateTracker *comparer = new ComparingUpdateTracker(&screen); + auto *comparer = new ComparingUpdateTracker(&screen); Region cursorReg; Server::detectScrolling.setParam(false); Server::detectHorizontal.setParam(false); - gettimeofday(&start, NULL); - runs = RUNS; - for (i = 0; i < runs; i++) { - memcpy(screenptr, i % 2 ? f1orig : f2orig, W * H * 4); - comparer->compare(true, cursorReg); - } - vlog.info("Analysis took %u ms (%u runs) (incl. memcpy overhead)", msSince(&start), runs); + benchmark("Analysis (incl. memcpy overhead)", RUNS, + [&screenptr, &comparer, &cursorReg, f1orig, f2orig](uint32_t i) { + memcpy(screenptr, i % 2 ? f1orig : f2orig, WIDTH * HEIGHT * 4); + comparer->compare(true, cursorReg); + }); Server::detectScrolling.setParam(true); - gettimeofday(&start, NULL); - runs = RUNS; - for (i = 0; i < runs; i++) { - memcpy(screenptr, i % 2 ? f1orig : f2orig, W * H * 4); - comparer->compare(false, cursorReg); - } - vlog.info("Analysis w/ scroll detection took %u ms (%u runs) (incl. memcpy overhead)", msSince(&start), runs); + benchmark("Analysis w/ scroll detection (incl. memcpy overhead)", RUNS, + [&screenptr, &comparer, &cursorReg, f1orig, f2orig](uint32_t i) { + memcpy(screenptr, i % 2 ? f1orig : f2orig, WIDTH * HEIGHT * 4); + comparer->compare(false, cursorReg); + }); Server::detectHorizontal.setParam(true); delete comparer; comparer = new ComparingUpdateTracker(&screen); - gettimeofday(&start, NULL); - runs = RUNS / 2; - for (i = 0; i < runs; i++) { - memcpy(screenptr, i % 2 ? f1orig : f2orig, W * H * 4); - comparer->compare(false, cursorReg); - } - vlog.info("Analysis w/ horizontal scroll detection took %u ms (%u runs) (incl. memcpy overhead)", msSince(&start), runs); + benchmark("Analysis w/ horizontal scroll detection (incl. memcpy overhead)", RUNS / 2, + [&screenptr, &comparer, &cursorReg, f1orig, f2orig](uint32_t i) { + memcpy(screenptr, i % 2 ? f1orig : f2orig, WIDTH * HEIGHT * 4); + comparer->compare(false, cursorReg); + }); + vlog.info("Before"); + doc.SaveFile("SelfBench.xml"); + vlog.info("after"); exit(0); } From 35b77ae244e43d803e1e8ec98061c1687bf08dd2 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 31 Mar 2025 03:50:58 +0500 Subject: [PATCH 115/167] KASM-6984 Add tinyxml2 library to the project --- third_party/tinyxml2/LICENSE.txt | 18 + third_party/tinyxml2/tinyxml2.cpp | 3019 +++++++++++++++++++++++++++++ third_party/tinyxml2/tinyxml2.h | 2383 +++++++++++++++++++++++ 3 files changed, 5420 insertions(+) create mode 100644 third_party/tinyxml2/LICENSE.txt create mode 100644 third_party/tinyxml2/tinyxml2.cpp create mode 100644 third_party/tinyxml2/tinyxml2.h diff --git a/third_party/tinyxml2/LICENSE.txt b/third_party/tinyxml2/LICENSE.txt new file mode 100644 index 0000000..85a6a36 --- /dev/null +++ b/third_party/tinyxml2/LICENSE.txt @@ -0,0 +1,18 @@ +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. diff --git a/third_party/tinyxml2/tinyxml2.cpp b/third_party/tinyxml2/tinyxml2.cpp new file mode 100644 index 0000000..8bb9635 --- /dev/null +++ b/third_party/tinyxml2/tinyxml2.cpp @@ -0,0 +1,3019 @@ +/* +Original code by Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxml2.h" + +#include // yes, this one new style header, is in the Android SDK. +#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__) || defined(__CC_ARM) +# include +# include +#else +# include +# include +#endif + +#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE) + // Microsoft Visual Studio, version 2005 and higher. Not WinCE. + /*int _snprintf_s( + char *buffer, + size_t sizeOfBuffer, + size_t count, + const char *format [, + argument] ... + );*/ + static inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... ) + { + va_list va; + va_start( va, format ); + const int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va ); + va_end( va ); + return result; + } + + static inline int TIXML_VSNPRINTF( char* buffer, size_t size, const char* format, va_list va ) + { + const int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va ); + return result; + } + + #define TIXML_VSCPRINTF _vscprintf + #define TIXML_SSCANF sscanf_s +#elif defined _MSC_VER + // Microsoft Visual Studio 2003 and earlier or WinCE + #define TIXML_SNPRINTF _snprintf + #define TIXML_VSNPRINTF _vsnprintf + #define TIXML_SSCANF sscanf + #if (_MSC_VER < 1400 ) && (!defined WINCE) + // Microsoft Visual Studio 2003 and not WinCE. + #define TIXML_VSCPRINTF _vscprintf // VS2003's C runtime has this, but VC6 C runtime or WinCE SDK doesn't have. + #else + // Microsoft Visual Studio 2003 and earlier or WinCE. + static inline int TIXML_VSCPRINTF( const char* format, va_list va ) + { + int len = 512; + for (;;) { + len = len*2; + char* str = new char[len](); + const int required = _vsnprintf(str, len, format, va); + delete[] str; + if ( required != -1 ) { + TIXMLASSERT( required >= 0 ); + len = required; + break; + } + } + TIXMLASSERT( len >= 0 ); + return len; + } + #endif +#else + // GCC version 3 and higher + //#warning( "Using sn* functions." ) + #define TIXML_SNPRINTF snprintf + #define TIXML_VSNPRINTF vsnprintf + static inline int TIXML_VSCPRINTF( const char* format, va_list va ) + { + int len = vsnprintf( 0, 0, format, va ); + TIXMLASSERT( len >= 0 ); + return len; + } + #define TIXML_SSCANF sscanf +#endif + +#if defined(_WIN64) + #define TIXML_FSEEK _fseeki64 + #define TIXML_FTELL _ftelli64 +#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__CYGWIN__) + #define TIXML_FSEEK fseeko + #define TIXML_FTELL ftello +#elif defined(__ANDROID__) && __ANDROID_API__ > 24 + #define TIXML_FSEEK fseeko64 + #define TIXML_FTELL ftello64 +#else + #define TIXML_FSEEK fseek + #define TIXML_FTELL ftell +#endif + + +static const char LINE_FEED = static_cast(0x0a); // all line endings are normalized to LF +static const char LF = LINE_FEED; +static const char CARRIAGE_RETURN = static_cast(0x0d); // CR gets filtered out +static const char CR = CARRIAGE_RETURN; +static const char SINGLE_QUOTE = '\''; +static const char DOUBLE_QUOTE = '\"'; + +// Bunch of unicode info at: +// http://www.unicode.org/faq/utf_bom.html +// ef bb bf (Microsoft "lead bytes") - designates UTF-8 + +static const unsigned char TIXML_UTF_LEAD_0 = 0xefU; +static const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; +static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; + +namespace tinyxml2 +{ + +struct Entity { + const char* pattern; + int length; + char value; +}; + +static const int NUM_ENTITIES = 5; +static const Entity entities[NUM_ENTITIES] = { + { "quot", 4, DOUBLE_QUOTE }, + { "amp", 3, '&' }, + { "apos", 4, SINGLE_QUOTE }, + { "lt", 2, '<' }, + { "gt", 2, '>' } +}; + + +StrPair::~StrPair() +{ + Reset(); +} + + +void StrPair::TransferTo( StrPair* other ) +{ + if ( this == other ) { + return; + } + // This in effect implements the assignment operator by "moving" + // ownership (as in auto_ptr). + + TIXMLASSERT( other != 0 ); + TIXMLASSERT( other->_flags == 0 ); + TIXMLASSERT( other->_start == 0 ); + TIXMLASSERT( other->_end == 0 ); + + other->Reset(); + + other->_flags = _flags; + other->_start = _start; + other->_end = _end; + + _flags = 0; + _start = 0; + _end = 0; +} + + +void StrPair::Reset() +{ + if ( _flags & NEEDS_DELETE ) { + delete [] _start; + } + _flags = 0; + _start = 0; + _end = 0; +} + + +void StrPair::SetStr( const char* str, int flags ) +{ + TIXMLASSERT( str ); + Reset(); + size_t len = strlen( str ); + TIXMLASSERT( _start == 0 ); + _start = new char[ len+1 ]; + memcpy( _start, str, len+1 ); + _end = _start + len; + _flags = flags | NEEDS_DELETE; +} + + +char* StrPair::ParseText( char* p, const char* endTag, int strFlags, int* curLineNumPtr ) +{ + TIXMLASSERT( p ); + TIXMLASSERT( endTag && *endTag ); + TIXMLASSERT(curLineNumPtr); + + char* start = p; + const char endChar = *endTag; + size_t length = strlen( endTag ); + + // Inner loop of text parsing. + while ( *p ) { + if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) { + Set( start, p, strFlags ); + return p + length; + } else if (*p == '\n') { + ++(*curLineNumPtr); + } + ++p; + TIXMLASSERT( p ); + } + return 0; +} + + +char* StrPair::ParseName( char* p ) +{ + if ( !p || !(*p) ) { + return 0; + } + if ( !XMLUtil::IsNameStartChar( static_cast(*p) ) ) { + return 0; + } + + char* const start = p; + ++p; + while ( *p && XMLUtil::IsNameChar( static_cast(*p) ) ) { + ++p; + } + + Set( start, p, 0 ); + return p; +} + + +void StrPair::CollapseWhitespace() +{ + // Adjusting _start would cause undefined behavior on delete[] + TIXMLASSERT( ( _flags & NEEDS_DELETE ) == 0 ); + // Trim leading space. + _start = XMLUtil::SkipWhiteSpace( _start, 0 ); + + if ( *_start ) { + const char* p = _start; // the read pointer + char* q = _start; // the write pointer + + while( *p ) { + if ( XMLUtil::IsWhiteSpace( *p )) { + p = XMLUtil::SkipWhiteSpace( p, 0 ); + if ( *p == 0 ) { + break; // don't write to q; this trims the trailing space. + } + *q = ' '; + ++q; + } + *q = *p; + ++q; + ++p; + } + *q = 0; + } +} + + +const char* StrPair::GetStr() +{ + TIXMLASSERT( _start ); + TIXMLASSERT( _end ); + if ( _flags & NEEDS_FLUSH ) { + *_end = 0; + _flags ^= NEEDS_FLUSH; + + if ( _flags ) { + const char* p = _start; // the read pointer + char* q = _start; // the write pointer + + while( p < _end ) { + if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) { + // CR-LF pair becomes LF + // CR alone becomes LF + // LF-CR becomes LF + if ( *(p+1) == LF ) { + p += 2; + } + else { + ++p; + } + *q = LF; + ++q; + } + else if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) { + if ( *(p+1) == CR ) { + p += 2; + } + else { + ++p; + } + *q = LF; + ++q; + } + else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) { + // Entities handled by tinyXML2: + // - special entities in the entity table [in/out] + // - numeric character reference [in] + // 中 or 中 + + if ( *(p+1) == '#' ) { + const int buflen = 10; + char buf[buflen] = { 0 }; + int len = 0; + const char* adjusted = const_cast( XMLUtil::GetCharacterRef( p, buf, &len ) ); + if ( adjusted == 0 ) { + *q = *p; + ++p; + ++q; + } + else { + TIXMLASSERT( 0 <= len && len <= buflen ); + TIXMLASSERT( q + len <= adjusted ); + p = adjusted; + memcpy( q, buf, len ); + q += len; + } + } + else { + bool entityFound = false; + for( int i = 0; i < NUM_ENTITIES; ++i ) { + const Entity& entity = entities[i]; + if ( strncmp( p + 1, entity.pattern, entity.length ) == 0 + && *( p + entity.length + 1 ) == ';' ) { + // Found an entity - convert. + *q = entity.value; + ++q; + p += entity.length + 2; + entityFound = true; + break; + } + } + if ( !entityFound ) { + // fixme: treat as error? + ++p; + ++q; + } + } + } + else { + *q = *p; + ++p; + ++q; + } + } + *q = 0; + } + // The loop below has plenty going on, and this + // is a less useful mode. Break it out. + if ( _flags & NEEDS_WHITESPACE_COLLAPSING ) { + CollapseWhitespace(); + } + _flags = (_flags & NEEDS_DELETE); + } + TIXMLASSERT( _start ); + return _start; +} + + + + +// --------- XMLUtil ----------- // + +const char* XMLUtil::writeBoolTrue = "true"; +const char* XMLUtil::writeBoolFalse = "false"; + +void XMLUtil::SetBoolSerialization(const char* writeTrue, const char* writeFalse) +{ + static const char* defTrue = "true"; + static const char* defFalse = "false"; + + writeBoolTrue = (writeTrue) ? writeTrue : defTrue; + writeBoolFalse = (writeFalse) ? writeFalse : defFalse; +} + + +const char* XMLUtil::ReadBOM( const char* p, bool* bom ) +{ + TIXMLASSERT( p ); + TIXMLASSERT( bom ); + *bom = false; + const unsigned char* pu = reinterpret_cast(p); + // Check for BOM: + if ( *(pu+0) == TIXML_UTF_LEAD_0 + && *(pu+1) == TIXML_UTF_LEAD_1 + && *(pu+2) == TIXML_UTF_LEAD_2 ) { + *bom = true; + p += 3; + } + TIXMLASSERT( p ); + return p; +} + + +void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) +{ + const unsigned long BYTE_MASK = 0xBF; + const unsigned long BYTE_MARK = 0x80; + const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; + + if (input < 0x80) { + *length = 1; + } + else if ( input < 0x800 ) { + *length = 2; + } + else if ( input < 0x10000 ) { + *length = 3; + } + else if ( input < 0x200000 ) { + *length = 4; + } + else { + *length = 0; // This code won't convert this correctly anyway. + return; + } + + output += *length; + + // Scary scary fall throughs are annotated with carefully designed comments + // to suppress compiler warnings such as -Wimplicit-fallthrough in gcc + switch (*length) { + case 4: + --output; + *output = static_cast((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + //fall through + case 3: + --output; + *output = static_cast((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + //fall through + case 2: + --output; + *output = static_cast((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + //fall through + case 1: + --output; + *output = static_cast(input | FIRST_BYTE_MARK[*length]); + break; + default: + TIXMLASSERT( false ); + } +} + + +const char* XMLUtil::GetCharacterRef(const char* p, char* value, int* length) +{ + // Assume an entity, and pull it out. + *length = 0; + + static const uint32_t MAX_CODE_POINT = 0x10FFFF; + + if (*(p + 1) == '#' && *(p + 2)) { + uint32_t ucs = 0; + ptrdiff_t delta = 0; + uint32_t mult = 1; + static const char SEMICOLON = ';'; + + bool hex = false; + uint32_t radix = 10; + const char* q = 0; + char terminator = '#'; + + if (*(p + 2) == 'x') { + // Hexadecimal. + hex = true; + radix = 16; + terminator = 'x'; + + q = p + 3; + } + else { + // Decimal. + q = p + 2; + } + if (!(*q)) { + return 0; + } + + q = strchr(q, SEMICOLON); + if (!q) { + return 0; + } + TIXMLASSERT(*q == SEMICOLON); + + delta = q - p; + --q; + + while (*q != terminator) { + uint32_t digit = 0; + + if (*q >= '0' && *q <= '9') { + digit = *q - '0'; + } + else if (hex && (*q >= 'a' && *q <= 'f')) { + digit = *q - 'a' + 10; + } + else if (hex && (*q >= 'A' && *q <= 'F')) { + digit = *q - 'A' + 10; + } + else { + return 0; + } + TIXMLASSERT(digit < radix); + + const unsigned int digitScaled = mult * digit; + ucs += digitScaled; + mult *= radix; + + // Security check: could a value exist that is out of range? + // Easily; limit to the MAX_CODE_POINT, which also allows for a + // bunch of leading zeroes. + if (mult > MAX_CODE_POINT) { + mult = MAX_CODE_POINT; + } + --q; + } + // Out of range: + if (ucs > MAX_CODE_POINT) { + return 0; + } + // convert the UCS to UTF-8 + ConvertUTF32ToUTF8(ucs, value, length); + if (length == 0) { + // If length is 0, there was an error. (Security? Bad input?) + // Fail safely. + return 0; + } + return p + delta + 1; + } + return p + 1; +} + +void XMLUtil::ToStr( int v, char* buffer, int bufferSize ) +{ + TIXML_SNPRINTF( buffer, bufferSize, "%d", v ); +} + + +void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize ) +{ + TIXML_SNPRINTF( buffer, bufferSize, "%u", v ); +} + + +void XMLUtil::ToStr( bool v, char* buffer, int bufferSize ) +{ + TIXML_SNPRINTF( buffer, bufferSize, "%s", v ? writeBoolTrue : writeBoolFalse); +} + +/* + ToStr() of a number is a very tricky topic. + https://github.com/leethomason/tinyxml2/issues/106 +*/ +void XMLUtil::ToStr( float v, char* buffer, int bufferSize ) +{ + TIXML_SNPRINTF( buffer, bufferSize, "%.8g", v ); +} + + +void XMLUtil::ToStr( double v, char* buffer, int bufferSize ) +{ + TIXML_SNPRINTF( buffer, bufferSize, "%.17g", v ); +} + + +void XMLUtil::ToStr( int64_t v, char* buffer, int bufferSize ) +{ + // horrible syntax trick to make the compiler happy about %lld + TIXML_SNPRINTF(buffer, bufferSize, "%lld", static_cast(v)); +} + +void XMLUtil::ToStr( uint64_t v, char* buffer, int bufferSize ) +{ + // horrible syntax trick to make the compiler happy about %llu + TIXML_SNPRINTF(buffer, bufferSize, "%llu", static_cast(v)); +} + +bool XMLUtil::ToInt(const char* str, int* value) +{ + if (IsPrefixHex(str)) { + unsigned v; + if (TIXML_SSCANF(str, "%x", &v) == 1) { + *value = static_cast(v); + return true; + } + } + else { + if (TIXML_SSCANF(str, "%d", value) == 1) { + return true; + } + } + return false; +} + +bool XMLUtil::ToUnsigned(const char* str, unsigned* value) +{ + if (TIXML_SSCANF(str, IsPrefixHex(str) ? "%x" : "%u", value) == 1) { + return true; + } + return false; +} + +bool XMLUtil::ToBool( const char* str, bool* value ) +{ + int ival = 0; + if ( ToInt( str, &ival )) { + *value = (ival==0) ? false : true; + return true; + } + static const char* TRUE_VALS[] = { "true", "True", "TRUE", 0 }; + static const char* FALSE_VALS[] = { "false", "False", "FALSE", 0 }; + + for (int i = 0; TRUE_VALS[i]; ++i) { + if (StringEqual(str, TRUE_VALS[i])) { + *value = true; + return true; + } + } + for (int i = 0; FALSE_VALS[i]; ++i) { + if (StringEqual(str, FALSE_VALS[i])) { + *value = false; + return true; + } + } + return false; +} + + +bool XMLUtil::ToFloat( const char* str, float* value ) +{ + if ( TIXML_SSCANF( str, "%f", value ) == 1 ) { + return true; + } + return false; +} + + +bool XMLUtil::ToDouble( const char* str, double* value ) +{ + if ( TIXML_SSCANF( str, "%lf", value ) == 1 ) { + return true; + } + return false; +} + + +bool XMLUtil::ToInt64(const char* str, int64_t* value) +{ + if (IsPrefixHex(str)) { + unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llx + if (TIXML_SSCANF(str, "%llx", &v) == 1) { + *value = static_cast(v); + return true; + } + } + else { + long long v = 0; // horrible syntax trick to make the compiler happy about %lld + if (TIXML_SSCANF(str, "%lld", &v) == 1) { + *value = static_cast(v); + return true; + } + } + return false; +} + + +bool XMLUtil::ToUnsigned64(const char* str, uint64_t* value) { + unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llu + if(TIXML_SSCANF(str, IsPrefixHex(str) ? "%llx" : "%llu", &v) == 1) { + *value = static_cast(v); + return true; + } + return false; +} + + +char* XMLDocument::Identify( char* p, XMLNode** node, bool first ) +{ + TIXMLASSERT( node ); + TIXMLASSERT( p ); + char* const start = p; + int const startLine = _parseCurLineNum; + p = XMLUtil::SkipWhiteSpace( p, &_parseCurLineNum ); + if( !*p ) { + *node = 0; + TIXMLASSERT( p ); + return p; + } + + // These strings define the matching patterns: + static const char* xmlHeader = { "( _commentPool ); + returnNode->_parseLineNum = _parseCurLineNum; + p += xmlHeaderLen; + } + else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) { + returnNode = CreateUnlinkedNode( _commentPool ); + returnNode->_parseLineNum = _parseCurLineNum; + p += commentHeaderLen; + } + else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) { + XMLText* text = CreateUnlinkedNode( _textPool ); + returnNode = text; + returnNode->_parseLineNum = _parseCurLineNum; + p += cdataHeaderLen; + text->SetCData( true ); + } + else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) { + returnNode = CreateUnlinkedNode( _commentPool ); + returnNode->_parseLineNum = _parseCurLineNum; + p += dtdHeaderLen; + } + else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) { + + // Preserve whitespace pedantically before closing tag, when it's immediately after opening tag + if (WhitespaceMode() == PEDANTIC_WHITESPACE && first && p != start && *(p + elementHeaderLen) == '/') { + returnNode = CreateUnlinkedNode(_textPool); + returnNode->_parseLineNum = startLine; + p = start; // Back it up, all the text counts. + _parseCurLineNum = startLine; + } + else { + returnNode = CreateUnlinkedNode(_elementPool); + returnNode->_parseLineNum = _parseCurLineNum; + p += elementHeaderLen; + } + } + else { + returnNode = CreateUnlinkedNode( _textPool ); + returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace character + p = start; // Back it up, all the text counts. + _parseCurLineNum = startLine; + } + + TIXMLASSERT( returnNode ); + TIXMLASSERT( p ); + *node = returnNode; + return p; +} + + +bool XMLDocument::Accept( XMLVisitor* visitor ) const +{ + TIXMLASSERT( visitor ); + if ( visitor->VisitEnter( *this ) ) { + for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) { + if ( !node->Accept( visitor ) ) { + break; + } + } + } + return visitor->VisitExit( *this ); +} + + +// --------- XMLNode ----------- // + +XMLNode::XMLNode( XMLDocument* doc ) : + _document( doc ), + _parent( 0 ), + _value(), + _parseLineNum( 0 ), + _firstChild( 0 ), _lastChild( 0 ), + _prev( 0 ), _next( 0 ), + _userData( 0 ), + _memPool( 0 ) +{ +} + + +XMLNode::~XMLNode() +{ + DeleteChildren(); + if ( _parent ) { + _parent->Unlink( this ); + } +} + +// ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2. + +int XMLNode::ChildElementCount(const char *value) const { + int count = 0; + + const XMLElement *e = FirstChildElement(value); + + while (e) { + e = e->NextSiblingElement(value); + count++; + } + + return count; +} + +int XMLNode::ChildElementCount() const { + int count = 0; + + const XMLElement *e = FirstChildElement(); + + while (e) { + e = e->NextSiblingElement(); + count++; + } + + return count; +} + +const char* XMLNode::Value() const +{ + // Edge case: XMLDocuments don't have a Value. Return null. + if ( this->ToDocument() ) + return 0; + return _value.GetStr(); +} + +void XMLNode::SetValue( const char* str, bool staticMem ) +{ + if ( staticMem ) { + _value.SetInternedStr( str ); + } + else { + _value.SetStr( str ); + } +} + +XMLNode* XMLNode::DeepClone(XMLDocument* target) const +{ + XMLNode* clone = this->ShallowClone(target); + if (!clone) return 0; + + for (const XMLNode* child = this->FirstChild(); child; child = child->NextSibling()) { + XMLNode* childClone = child->DeepClone(target); + TIXMLASSERT(childClone); + clone->InsertEndChild(childClone); + } + return clone; +} + +void XMLNode::DeleteChildren() +{ + while( _firstChild ) { + TIXMLASSERT( _lastChild ); + DeleteChild( _firstChild ); + } + _firstChild = _lastChild = 0; +} + + +void XMLNode::Unlink( XMLNode* child ) +{ + TIXMLASSERT( child ); + TIXMLASSERT( child->_document == _document ); + TIXMLASSERT( child->_parent == this ); + if ( child == _firstChild ) { + _firstChild = _firstChild->_next; + } + if ( child == _lastChild ) { + _lastChild = _lastChild->_prev; + } + + if ( child->_prev ) { + child->_prev->_next = child->_next; + } + if ( child->_next ) { + child->_next->_prev = child->_prev; + } + child->_next = 0; + child->_prev = 0; + child->_parent = 0; +} + + +void XMLNode::DeleteChild( XMLNode* node ) +{ + TIXMLASSERT( node ); + TIXMLASSERT( node->_document == _document ); + TIXMLASSERT( node->_parent == this ); + Unlink( node ); + TIXMLASSERT(node->_prev == 0); + TIXMLASSERT(node->_next == 0); + TIXMLASSERT(node->_parent == 0); + DeleteNode( node ); +} + + +XMLNode* XMLNode::InsertEndChild( XMLNode* addThis ) +{ + TIXMLASSERT( addThis ); + if ( addThis->_document != _document ) { + TIXMLASSERT( false ); + return 0; + } + InsertChildPreamble( addThis ); + + if ( _lastChild ) { + TIXMLASSERT( _firstChild ); + TIXMLASSERT( _lastChild->_next == 0 ); + _lastChild->_next = addThis; + addThis->_prev = _lastChild; + _lastChild = addThis; + + addThis->_next = 0; + } + else { + TIXMLASSERT( _firstChild == 0 ); + _firstChild = _lastChild = addThis; + + addThis->_prev = 0; + addThis->_next = 0; + } + addThis->_parent = this; + return addThis; +} + + +XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis ) +{ + TIXMLASSERT( addThis ); + if ( addThis->_document != _document ) { + TIXMLASSERT( false ); + return 0; + } + InsertChildPreamble( addThis ); + + if ( _firstChild ) { + TIXMLASSERT( _lastChild ); + TIXMLASSERT( _firstChild->_prev == 0 ); + + _firstChild->_prev = addThis; + addThis->_next = _firstChild; + _firstChild = addThis; + + addThis->_prev = 0; + } + else { + TIXMLASSERT( _lastChild == 0 ); + _firstChild = _lastChild = addThis; + + addThis->_prev = 0; + addThis->_next = 0; + } + addThis->_parent = this; + return addThis; +} + + +XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ) +{ + TIXMLASSERT( addThis ); + if ( addThis->_document != _document ) { + TIXMLASSERT( false ); + return 0; + } + + TIXMLASSERT( afterThis ); + + if ( afterThis->_parent != this ) { + TIXMLASSERT( false ); + return 0; + } + if ( afterThis == addThis ) { + // Current state: BeforeThis -> AddThis -> OneAfterAddThis + // Now AddThis must disappear from it's location and then + // reappear between BeforeThis and OneAfterAddThis. + // So just leave it where it is. + return addThis; + } + + if ( afterThis->_next == 0 ) { + // The last node or the only node. + return InsertEndChild( addThis ); + } + InsertChildPreamble( addThis ); + addThis->_prev = afterThis; + addThis->_next = afterThis->_next; + afterThis->_next->_prev = addThis; + afterThis->_next = addThis; + addThis->_parent = this; + return addThis; +} + + + + +const XMLElement* XMLNode::FirstChildElement( const char* name ) const +{ + for( const XMLNode* node = _firstChild; node; node = node->_next ) { + const XMLElement* element = node->ToElementWithName( name ); + if ( element ) { + return element; + } + } + return 0; +} + + +const XMLElement* XMLNode::LastChildElement( const char* name ) const +{ + for( const XMLNode* node = _lastChild; node; node = node->_prev ) { + const XMLElement* element = node->ToElementWithName( name ); + if ( element ) { + return element; + } + } + return 0; +} + + +const XMLElement* XMLNode::NextSiblingElement( const char* name ) const +{ + for( const XMLNode* node = _next; node; node = node->_next ) { + const XMLElement* element = node->ToElementWithName( name ); + if ( element ) { + return element; + } + } + return 0; +} + + +const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const +{ + for( const XMLNode* node = _prev; node; node = node->_prev ) { + const XMLElement* element = node->ToElementWithName( name ); + if ( element ) { + return element; + } + } + return 0; +} + + +char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) +{ + // This is a recursive method, but thinking about it "at the current level" + // it is a pretty simple flat list: + // + // + // + // With a special case: + // + // + // + // + // Where the closing element (/foo) *must* be the next thing after the opening + // element, and the names must match. BUT the tricky bit is that the closing + // element will be read by the child. + // + // 'endTag' is the end tag for this node, it is returned by a call to a child. + // 'parentEnd' is the end tag for the parent, which is filled in and returned. + + XMLDocument::DepthTracker tracker(_document); + if (_document->Error()) + return 0; + + bool first = true; + while( p && *p ) { + XMLNode* node = 0; + + p = _document->Identify( p, &node, first ); + TIXMLASSERT( p ); + if ( node == 0 ) { + break; + } + first = false; + + const int initialLineNum = node->_parseLineNum; + + StrPair endTag; + p = node->ParseDeep( p, &endTag, curLineNumPtr ); + if ( !p ) { + _document->DeleteNode( node ); + if ( !_document->Error() ) { + _document->SetError( XML_ERROR_PARSING, initialLineNum, 0); + } + break; + } + + const XMLDeclaration* const decl = node->ToDeclaration(); + if ( decl ) { + // Declarations are only allowed at document level + // + // Multiple declarations are allowed but all declarations + // must occur before anything else. + // + // Optimized due to a security test case. If the first node is + // a declaration, and the last node is a declaration, then only + // declarations have so far been added. + bool wellLocated = false; + + if (ToDocument()) { + if (FirstChild()) { + wellLocated = + FirstChild() && + FirstChild()->ToDeclaration() && + LastChild() && + LastChild()->ToDeclaration(); + } + else { + wellLocated = true; + } + } + if ( !wellLocated ) { + _document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, "XMLDeclaration value=%s", decl->Value()); + _document->DeleteNode( node ); + break; + } + } + + XMLElement* ele = node->ToElement(); + if ( ele ) { + // We read the end tag. Return it to the parent. + if ( ele->ClosingType() == XMLElement::CLOSING ) { + if ( parentEndTag ) { + ele->_value.TransferTo( parentEndTag ); + } + node->_memPool->SetTracked(); // created and then immediately deleted. + DeleteNode( node ); + return p; + } + + // Handle an end tag returned to this level. + // And handle a bunch of annoying errors. + bool mismatch = false; + if ( endTag.Empty() ) { + if ( ele->ClosingType() == XMLElement::OPEN ) { + mismatch = true; + } + } + else { + if ( ele->ClosingType() != XMLElement::OPEN ) { + mismatch = true; + } + else if ( !XMLUtil::StringEqual( endTag.GetStr(), ele->Name() ) ) { + mismatch = true; + } + } + if ( mismatch ) { + _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "XMLElement name=%s", ele->Name()); + _document->DeleteNode( node ); + break; + } + } + InsertEndChild( node ); + } + return 0; +} + +/*static*/ void XMLNode::DeleteNode( XMLNode* node ) +{ + if ( node == 0 ) { + return; + } + TIXMLASSERT(node->_document); + if (!node->ToDocument()) { + node->_document->MarkInUse(node); + } + + MemPool* pool = node->_memPool; + node->~XMLNode(); + pool->Free( node ); +} + +void XMLNode::InsertChildPreamble( XMLNode* insertThis ) const +{ + TIXMLASSERT( insertThis ); + TIXMLASSERT( insertThis->_document == _document ); + + if (insertThis->_parent) { + insertThis->_parent->Unlink( insertThis ); + } + else { + insertThis->_document->MarkInUse(insertThis); + insertThis->_memPool->SetTracked(); + } +} + +const XMLElement* XMLNode::ToElementWithName( const char* name ) const +{ + const XMLElement* element = this->ToElement(); + if ( element == 0 ) { + return 0; + } + if ( name == 0 ) { + return element; + } + if ( XMLUtil::StringEqual( element->Name(), name ) ) { + return element; + } + return 0; +} + +// --------- XMLText ---------- // +char* XMLText::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) +{ + if ( this->CData() ) { + p = _value.ParseText( p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); + if ( !p ) { + _document->SetError( XML_ERROR_PARSING_CDATA, _parseLineNum, 0 ); + } + return p; + } + else { + int flags = _document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES; + if ( _document->WhitespaceMode() == COLLAPSE_WHITESPACE ) { + flags |= StrPair::NEEDS_WHITESPACE_COLLAPSING; + } + + p = _value.ParseText( p, "<", flags, curLineNumPtr ); + if ( p && *p ) { + return p-1; + } + if ( !p ) { + _document->SetError( XML_ERROR_PARSING_TEXT, _parseLineNum, 0 ); + } + } + return 0; +} + + +XMLNode* XMLText::ShallowClone( XMLDocument* doc ) const +{ + if ( !doc ) { + doc = _document; + } + XMLText* text = doc->NewText( Value() ); // fixme: this will always allocate memory. Intern? + text->SetCData( this->CData() ); + return text; +} + + +bool XMLText::ShallowEqual( const XMLNode* compare ) const +{ + TIXMLASSERT( compare ); + const XMLText* text = compare->ToText(); + return ( text && XMLUtil::StringEqual( text->Value(), Value() ) ); +} + + +bool XMLText::Accept( XMLVisitor* visitor ) const +{ + TIXMLASSERT( visitor ); + return visitor->Visit( *this ); +} + + +// --------- XMLComment ---------- // + +XMLComment::XMLComment( XMLDocument* doc ) : XMLNode( doc ) +{ +} + + +XMLComment::~XMLComment() +{ +} + + +char* XMLComment::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) +{ + // Comment parses as text. + p = _value.ParseText( p, "-->", StrPair::COMMENT, curLineNumPtr ); + if ( p == 0 ) { + _document->SetError( XML_ERROR_PARSING_COMMENT, _parseLineNum, 0 ); + } + return p; +} + + +XMLNode* XMLComment::ShallowClone( XMLDocument* doc ) const +{ + if ( !doc ) { + doc = _document; + } + XMLComment* comment = doc->NewComment( Value() ); // fixme: this will always allocate memory. Intern? + return comment; +} + + +bool XMLComment::ShallowEqual( const XMLNode* compare ) const +{ + TIXMLASSERT( compare ); + const XMLComment* comment = compare->ToComment(); + return ( comment && XMLUtil::StringEqual( comment->Value(), Value() )); +} + + +bool XMLComment::Accept( XMLVisitor* visitor ) const +{ + TIXMLASSERT( visitor ); + return visitor->Visit( *this ); +} + + +// --------- XMLDeclaration ---------- // + +XMLDeclaration::XMLDeclaration( XMLDocument* doc ) : XMLNode( doc ) +{ +} + + +XMLDeclaration::~XMLDeclaration() +{ + //printf( "~XMLDeclaration\n" ); +} + + +char* XMLDeclaration::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) +{ + // Declaration parses as text. + p = _value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); + if ( p == 0 ) { + _document->SetError( XML_ERROR_PARSING_DECLARATION, _parseLineNum, 0 ); + } + return p; +} + + +XMLNode* XMLDeclaration::ShallowClone( XMLDocument* doc ) const +{ + if ( !doc ) { + doc = _document; + } + XMLDeclaration* dec = doc->NewDeclaration( Value() ); // fixme: this will always allocate memory. Intern? + return dec; +} + + +bool XMLDeclaration::ShallowEqual( const XMLNode* compare ) const +{ + TIXMLASSERT( compare ); + const XMLDeclaration* declaration = compare->ToDeclaration(); + return ( declaration && XMLUtil::StringEqual( declaration->Value(), Value() )); +} + + + +bool XMLDeclaration::Accept( XMLVisitor* visitor ) const +{ + TIXMLASSERT( visitor ); + return visitor->Visit( *this ); +} + +// --------- XMLUnknown ---------- // + +XMLUnknown::XMLUnknown( XMLDocument* doc ) : XMLNode( doc ) +{ +} + + +XMLUnknown::~XMLUnknown() +{ +} + + +char* XMLUnknown::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) +{ + // Unknown parses as text. + p = _value.ParseText( p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); + if ( !p ) { + _document->SetError( XML_ERROR_PARSING_UNKNOWN, _parseLineNum, 0 ); + } + return p; +} + + +XMLNode* XMLUnknown::ShallowClone( XMLDocument* doc ) const +{ + if ( !doc ) { + doc = _document; + } + XMLUnknown* text = doc->NewUnknown( Value() ); // fixme: this will always allocate memory. Intern? + return text; +} + + +bool XMLUnknown::ShallowEqual( const XMLNode* compare ) const +{ + TIXMLASSERT( compare ); + const XMLUnknown* unknown = compare->ToUnknown(); + return ( unknown && XMLUtil::StringEqual( unknown->Value(), Value() )); +} + + +bool XMLUnknown::Accept( XMLVisitor* visitor ) const +{ + TIXMLASSERT( visitor ); + return visitor->Visit( *this ); +} + +// --------- XMLAttribute ---------- // + +const char* XMLAttribute::Name() const +{ + return _name.GetStr(); +} + +const char* XMLAttribute::Value() const +{ + return _value.GetStr(); +} + +char* XMLAttribute::ParseDeep( char* p, bool processEntities, int* curLineNumPtr ) +{ + // Parse using the name rules: bug fix, was using ParseText before + p = _name.ParseName( p ); + if ( !p || !*p ) { + return 0; + } + + // Skip white space before = + p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); + if ( *p != '=' ) { + return 0; + } + + ++p; // move up to opening quote + p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); + if ( *p != '\"' && *p != '\'' ) { + return 0; + } + + const char endTag[2] = { *p, 0 }; + ++p; // move past opening quote + + p = _value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES, curLineNumPtr ); + return p; +} + + +void XMLAttribute::SetName( const char* n ) +{ + _name.SetStr( n ); +} + + +XMLError XMLAttribute::QueryIntValue( int* value ) const +{ + if ( XMLUtil::ToInt( Value(), value )) { + return XML_SUCCESS; + } + return XML_WRONG_ATTRIBUTE_TYPE; +} + + +XMLError XMLAttribute::QueryUnsignedValue( unsigned int* value ) const +{ + if ( XMLUtil::ToUnsigned( Value(), value )) { + return XML_SUCCESS; + } + return XML_WRONG_ATTRIBUTE_TYPE; +} + + +XMLError XMLAttribute::QueryInt64Value(int64_t* value) const +{ + if (XMLUtil::ToInt64(Value(), value)) { + return XML_SUCCESS; + } + return XML_WRONG_ATTRIBUTE_TYPE; +} + + +XMLError XMLAttribute::QueryUnsigned64Value(uint64_t* value) const +{ + if(XMLUtil::ToUnsigned64(Value(), value)) { + return XML_SUCCESS; + } + return XML_WRONG_ATTRIBUTE_TYPE; +} + + +XMLError XMLAttribute::QueryBoolValue( bool* value ) const +{ + if ( XMLUtil::ToBool( Value(), value )) { + return XML_SUCCESS; + } + return XML_WRONG_ATTRIBUTE_TYPE; +} + + +XMLError XMLAttribute::QueryFloatValue( float* value ) const +{ + if ( XMLUtil::ToFloat( Value(), value )) { + return XML_SUCCESS; + } + return XML_WRONG_ATTRIBUTE_TYPE; +} + + +XMLError XMLAttribute::QueryDoubleValue( double* value ) const +{ + if ( XMLUtil::ToDouble( Value(), value )) { + return XML_SUCCESS; + } + return XML_WRONG_ATTRIBUTE_TYPE; +} + + +void XMLAttribute::SetAttribute( const char* v ) +{ + _value.SetStr( v ); +} + + +void XMLAttribute::SetAttribute( int v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + _value.SetStr( buf ); +} + + +void XMLAttribute::SetAttribute( unsigned v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + _value.SetStr( buf ); +} + + +void XMLAttribute::SetAttribute(int64_t v) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr(v, buf, BUF_SIZE); + _value.SetStr(buf); +} + +void XMLAttribute::SetAttribute(uint64_t v) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr(v, buf, BUF_SIZE); + _value.SetStr(buf); +} + + +void XMLAttribute::SetAttribute( bool v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + _value.SetStr( buf ); +} + +void XMLAttribute::SetAttribute( double v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + _value.SetStr( buf ); +} + +void XMLAttribute::SetAttribute( float v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + _value.SetStr( buf ); +} + + +// --------- XMLElement ---------- // +XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ), + _closingType( OPEN ), + _rootAttribute( 0 ) +{ +} + + +XMLElement::~XMLElement() +{ + while( _rootAttribute ) { + XMLAttribute* next = _rootAttribute->_next; + DeleteAttribute( _rootAttribute ); + _rootAttribute = next; + } +} + + +const XMLAttribute* XMLElement::FindAttribute( const char* name ) const +{ + for( XMLAttribute* a = _rootAttribute; a; a = a->_next ) { + if ( XMLUtil::StringEqual( a->Name(), name ) ) { + return a; + } + } + return 0; +} + + +const char* XMLElement::Attribute( const char* name, const char* value ) const +{ + const XMLAttribute* a = FindAttribute( name ); + if ( !a ) { + return 0; + } + if ( !value || XMLUtil::StringEqual( a->Value(), value )) { + return a->Value(); + } + return 0; +} + +int XMLElement::IntAttribute(const char* name, int defaultValue) const +{ + int i = defaultValue; + QueryIntAttribute(name, &i); + return i; +} + +unsigned XMLElement::UnsignedAttribute(const char* name, unsigned defaultValue) const +{ + unsigned i = defaultValue; + QueryUnsignedAttribute(name, &i); + return i; +} + +int64_t XMLElement::Int64Attribute(const char* name, int64_t defaultValue) const +{ + int64_t i = defaultValue; + QueryInt64Attribute(name, &i); + return i; +} + +uint64_t XMLElement::Unsigned64Attribute(const char* name, uint64_t defaultValue) const +{ + uint64_t i = defaultValue; + QueryUnsigned64Attribute(name, &i); + return i; +} + +bool XMLElement::BoolAttribute(const char* name, bool defaultValue) const +{ + bool b = defaultValue; + QueryBoolAttribute(name, &b); + return b; +} + +double XMLElement::DoubleAttribute(const char* name, double defaultValue) const +{ + double d = defaultValue; + QueryDoubleAttribute(name, &d); + return d; +} + +float XMLElement::FloatAttribute(const char* name, float defaultValue) const +{ + float f = defaultValue; + QueryFloatAttribute(name, &f); + return f; +} + +const char* XMLElement::GetText() const +{ + /* skip comment node */ + const XMLNode* node = FirstChild(); + while (node) { + if (node->ToComment()) { + node = node->NextSibling(); + continue; + } + break; + } + + if ( node && node->ToText() ) { + return node->Value(); + } + return 0; +} + + +void XMLElement::SetText( const char* inText ) +{ + if ( FirstChild() && FirstChild()->ToText() ) + FirstChild()->SetValue( inText ); + else { + XMLText* theText = GetDocument()->NewText( inText ); + InsertFirstChild( theText ); + } +} + + +void XMLElement::SetText( int v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + SetText( buf ); +} + + +void XMLElement::SetText( unsigned v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + SetText( buf ); +} + + +void XMLElement::SetText(int64_t v) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr(v, buf, BUF_SIZE); + SetText(buf); +} + +void XMLElement::SetText(uint64_t v) { + char buf[BUF_SIZE]; + XMLUtil::ToStr(v, buf, BUF_SIZE); + SetText(buf); +} + + +void XMLElement::SetText( bool v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + SetText( buf ); +} + + +void XMLElement::SetText( float v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + SetText( buf ); +} + + +void XMLElement::SetText( double v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + SetText( buf ); +} + + +XMLError XMLElement::QueryIntText( int* ival ) const +{ + if ( FirstChild() && FirstChild()->ToText() ) { + const char* t = FirstChild()->Value(); + if ( XMLUtil::ToInt( t, ival ) ) { + return XML_SUCCESS; + } + return XML_CAN_NOT_CONVERT_TEXT; + } + return XML_NO_TEXT_NODE; +} + + +XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const +{ + if ( FirstChild() && FirstChild()->ToText() ) { + const char* t = FirstChild()->Value(); + if ( XMLUtil::ToUnsigned( t, uval ) ) { + return XML_SUCCESS; + } + return XML_CAN_NOT_CONVERT_TEXT; + } + return XML_NO_TEXT_NODE; +} + + +XMLError XMLElement::QueryInt64Text(int64_t* ival) const +{ + if (FirstChild() && FirstChild()->ToText()) { + const char* t = FirstChild()->Value(); + if (XMLUtil::ToInt64(t, ival)) { + return XML_SUCCESS; + } + return XML_CAN_NOT_CONVERT_TEXT; + } + return XML_NO_TEXT_NODE; +} + + +XMLError XMLElement::QueryUnsigned64Text(uint64_t* uval) const +{ + if(FirstChild() && FirstChild()->ToText()) { + const char* t = FirstChild()->Value(); + if(XMLUtil::ToUnsigned64(t, uval)) { + return XML_SUCCESS; + } + return XML_CAN_NOT_CONVERT_TEXT; + } + return XML_NO_TEXT_NODE; +} + + +XMLError XMLElement::QueryBoolText( bool* bval ) const +{ + if ( FirstChild() && FirstChild()->ToText() ) { + const char* t = FirstChild()->Value(); + if ( XMLUtil::ToBool( t, bval ) ) { + return XML_SUCCESS; + } + return XML_CAN_NOT_CONVERT_TEXT; + } + return XML_NO_TEXT_NODE; +} + + +XMLError XMLElement::QueryDoubleText( double* dval ) const +{ + if ( FirstChild() && FirstChild()->ToText() ) { + const char* t = FirstChild()->Value(); + if ( XMLUtil::ToDouble( t, dval ) ) { + return XML_SUCCESS; + } + return XML_CAN_NOT_CONVERT_TEXT; + } + return XML_NO_TEXT_NODE; +} + + +XMLError XMLElement::QueryFloatText( float* fval ) const +{ + if ( FirstChild() && FirstChild()->ToText() ) { + const char* t = FirstChild()->Value(); + if ( XMLUtil::ToFloat( t, fval ) ) { + return XML_SUCCESS; + } + return XML_CAN_NOT_CONVERT_TEXT; + } + return XML_NO_TEXT_NODE; +} + +int XMLElement::IntText(int defaultValue) const +{ + int i = defaultValue; + QueryIntText(&i); + return i; +} + +unsigned XMLElement::UnsignedText(unsigned defaultValue) const +{ + unsigned i = defaultValue; + QueryUnsignedText(&i); + return i; +} + +int64_t XMLElement::Int64Text(int64_t defaultValue) const +{ + int64_t i = defaultValue; + QueryInt64Text(&i); + return i; +} + +uint64_t XMLElement::Unsigned64Text(uint64_t defaultValue) const +{ + uint64_t i = defaultValue; + QueryUnsigned64Text(&i); + return i; +} + +bool XMLElement::BoolText(bool defaultValue) const +{ + bool b = defaultValue; + QueryBoolText(&b); + return b; +} + +double XMLElement::DoubleText(double defaultValue) const +{ + double d = defaultValue; + QueryDoubleText(&d); + return d; +} + +float XMLElement::FloatText(float defaultValue) const +{ + float f = defaultValue; + QueryFloatText(&f); + return f; +} + + +XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name ) +{ + XMLAttribute* last = 0; + XMLAttribute* attrib = 0; + for( attrib = _rootAttribute; + attrib; + last = attrib, attrib = attrib->_next ) { + if ( XMLUtil::StringEqual( attrib->Name(), name ) ) { + break; + } + } + if ( !attrib ) { + attrib = CreateAttribute(); + TIXMLASSERT( attrib ); + if ( last ) { + TIXMLASSERT( last->_next == 0 ); + last->_next = attrib; + } + else { + TIXMLASSERT( _rootAttribute == 0 ); + _rootAttribute = attrib; + } + attrib->SetName( name ); + } + return attrib; +} + + +void XMLElement::DeleteAttribute( const char* name ) +{ + XMLAttribute* prev = 0; + for( XMLAttribute* a=_rootAttribute; a; a=a->_next ) { + if ( XMLUtil::StringEqual( name, a->Name() ) ) { + if ( prev ) { + prev->_next = a->_next; + } + else { + _rootAttribute = a->_next; + } + DeleteAttribute( a ); + break; + } + prev = a; + } +} + + +char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr ) +{ + XMLAttribute* prevAttribute = 0; + + // Read the attributes. + while( p ) { + p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); + if ( !(*p) ) { + _document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, "XMLElement name=%s", Name() ); + return 0; + } + + // attribute. + if (XMLUtil::IsNameStartChar( static_cast(*p) ) ) { + XMLAttribute* attrib = CreateAttribute(); + TIXMLASSERT( attrib ); + attrib->_parseLineNum = _document->_parseCurLineNum; + + const int attrLineNum = attrib->_parseLineNum; + + p = attrib->ParseDeep( p, _document->ProcessEntities(), curLineNumPtr ); + if ( !p || Attribute( attrib->Name() ) ) { + DeleteAttribute( attrib ); + _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, attrLineNum, "XMLElement name=%s", Name() ); + return 0; + } + // There is a minor bug here: if the attribute in the source xml + // document is duplicated, it will not be detected and the + // attribute will be doubly added. However, tracking the 'prevAttribute' + // avoids re-scanning the attribute list. Preferring performance for + // now, may reconsider in the future. + if ( prevAttribute ) { + TIXMLASSERT( prevAttribute->_next == 0 ); + prevAttribute->_next = attrib; + } + else { + TIXMLASSERT( _rootAttribute == 0 ); + _rootAttribute = attrib; + } + prevAttribute = attrib; + } + // end of the tag + else if ( *p == '>' ) { + ++p; + break; + } + // end of the tag + else if ( *p == '/' && *(p+1) == '>' ) { + _closingType = CLOSED; + return p+2; // done; sealed element. + } + else { + _document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, 0 ); + return 0; + } + } + return p; +} + +void XMLElement::DeleteAttribute( XMLAttribute* attribute ) +{ + if ( attribute == 0 ) { + return; + } + MemPool* pool = attribute->_memPool; + attribute->~XMLAttribute(); + pool->Free( attribute ); +} + +XMLAttribute* XMLElement::CreateAttribute() +{ + TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() ); + XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute(); + TIXMLASSERT( attrib ); + attrib->_memPool = &_document->_attributePool; + attrib->_memPool->SetTracked(); + return attrib; +} + + +XMLElement* XMLElement::InsertNewChildElement(const char* name) +{ + XMLElement* node = _document->NewElement(name); + return InsertEndChild(node) ? node : 0; +} + +XMLComment* XMLElement::InsertNewComment(const char* comment) +{ + XMLComment* node = _document->NewComment(comment); + return InsertEndChild(node) ? node : 0; +} + +XMLText* XMLElement::InsertNewText(const char* text) +{ + XMLText* node = _document->NewText(text); + return InsertEndChild(node) ? node : 0; +} + +XMLDeclaration* XMLElement::InsertNewDeclaration(const char* text) +{ + XMLDeclaration* node = _document->NewDeclaration(text); + return InsertEndChild(node) ? node : 0; +} + +XMLUnknown* XMLElement::InsertNewUnknown(const char* text) +{ + XMLUnknown* node = _document->NewUnknown(text); + return InsertEndChild(node) ? node : 0; +} + + + +// +// +// foobar +// +char* XMLElement::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) +{ + // Read the element name. + p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); + + // The closing element is the form. It is + // parsed just like a regular element then deleted from + // the DOM. + if ( *p == '/' ) { + _closingType = CLOSING; + ++p; + } + + p = _value.ParseName( p ); + if ( _value.Empty() ) { + return 0; + } + + p = ParseAttributes( p, curLineNumPtr ); + if ( !p || !*p || _closingType != OPEN ) { + return p; + } + + p = XMLNode::ParseDeep( p, parentEndTag, curLineNumPtr ); + return p; +} + + + +XMLNode* XMLElement::ShallowClone( XMLDocument* doc ) const +{ + if ( !doc ) { + doc = _document; + } + XMLElement* element = doc->NewElement( Value() ); // fixme: this will always allocate memory. Intern? + for( const XMLAttribute* a=FirstAttribute(); a; a=a->Next() ) { + element->SetAttribute( a->Name(), a->Value() ); // fixme: this will always allocate memory. Intern? + } + return element; +} + + +bool XMLElement::ShallowEqual( const XMLNode* compare ) const +{ + TIXMLASSERT( compare ); + const XMLElement* other = compare->ToElement(); + if ( other && XMLUtil::StringEqual( other->Name(), Name() )) { + + const XMLAttribute* a=FirstAttribute(); + const XMLAttribute* b=other->FirstAttribute(); + + while ( a && b ) { + if ( !XMLUtil::StringEqual( a->Value(), b->Value() ) ) { + return false; + } + a = a->Next(); + b = b->Next(); + } + if ( a || b ) { + // different count + return false; + } + return true; + } + return false; +} + + +bool XMLElement::Accept( XMLVisitor* visitor ) const +{ + TIXMLASSERT( visitor ); + if ( visitor->VisitEnter( *this, _rootAttribute ) ) { + for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) { + if ( !node->Accept( visitor ) ) { + break; + } + } + } + return visitor->VisitExit( *this ); +} + + +// --------- XMLDocument ----------- // + +// Warning: List must match 'enum XMLError' +const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = { + "XML_SUCCESS", + "XML_NO_ATTRIBUTE", + "XML_WRONG_ATTRIBUTE_TYPE", + "XML_ERROR_FILE_NOT_FOUND", + "XML_ERROR_FILE_COULD_NOT_BE_OPENED", + "XML_ERROR_FILE_READ_ERROR", + "XML_ERROR_PARSING_ELEMENT", + "XML_ERROR_PARSING_ATTRIBUTE", + "XML_ERROR_PARSING_TEXT", + "XML_ERROR_PARSING_CDATA", + "XML_ERROR_PARSING_COMMENT", + "XML_ERROR_PARSING_DECLARATION", + "XML_ERROR_PARSING_UNKNOWN", + "XML_ERROR_EMPTY_DOCUMENT", + "XML_ERROR_MISMATCHED_ELEMENT", + "XML_ERROR_PARSING", + "XML_CAN_NOT_CONVERT_TEXT", + "XML_NO_TEXT_NODE", + "XML_ELEMENT_DEPTH_EXCEEDED" +}; + + +XMLDocument::XMLDocument( bool processEntities, Whitespace whitespaceMode ) : + XMLNode( 0 ), + _writeBOM( false ), + _processEntities( processEntities ), + _errorID(XML_SUCCESS), + _whitespaceMode( whitespaceMode ), + _errorStr(), + _errorLineNum( 0 ), + _charBuffer( 0 ), + _parseCurLineNum( 0 ), + _parsingDepth(0), + _unlinked(), + _elementPool(), + _attributePool(), + _textPool(), + _commentPool() +{ + // avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+) + _document = this; +} + + +XMLDocument::~XMLDocument() +{ + Clear(); +} + + +void XMLDocument::MarkInUse(const XMLNode* const node) +{ + TIXMLASSERT(node); + TIXMLASSERT(node->_parent == 0); + + for (size_t i = 0; i < _unlinked.Size(); ++i) { + if (node == _unlinked[i]) { + _unlinked.SwapRemove(i); + break; + } + } +} + +void XMLDocument::Clear() +{ + DeleteChildren(); + while( _unlinked.Size()) { + DeleteNode(_unlinked[0]); // Will remove from _unlinked as part of delete. + } + +#ifdef TINYXML2_DEBUG + const bool hadError = Error(); +#endif + ClearError(); + + delete [] _charBuffer; + _charBuffer = 0; + _parsingDepth = 0; + +#if 0 + _textPool.Trace( "text" ); + _elementPool.Trace( "element" ); + _commentPool.Trace( "comment" ); + _attributePool.Trace( "attribute" ); +#endif + +#ifdef TINYXML2_DEBUG + if ( !hadError ) { + TIXMLASSERT( _elementPool.CurrentAllocs() == _elementPool.Untracked() ); + TIXMLASSERT( _attributePool.CurrentAllocs() == _attributePool.Untracked() ); + TIXMLASSERT( _textPool.CurrentAllocs() == _textPool.Untracked() ); + TIXMLASSERT( _commentPool.CurrentAllocs() == _commentPool.Untracked() ); + } +#endif +} + + +void XMLDocument::DeepCopy(XMLDocument* target) const +{ + TIXMLASSERT(target); + if (target == this) { + return; // technically success - a no-op. + } + + target->Clear(); + for (const XMLNode* node = this->FirstChild(); node; node = node->NextSibling()) { + target->InsertEndChild(node->DeepClone(target)); + } +} + +XMLElement* XMLDocument::NewElement( const char* name ) +{ + XMLElement* ele = CreateUnlinkedNode( _elementPool ); + ele->SetName( name ); + return ele; +} + + +XMLComment* XMLDocument::NewComment( const char* str ) +{ + XMLComment* comment = CreateUnlinkedNode( _commentPool ); + comment->SetValue( str ); + return comment; +} + + +XMLText* XMLDocument::NewText( const char* str ) +{ + XMLText* text = CreateUnlinkedNode( _textPool ); + text->SetValue( str ); + return text; +} + + +XMLDeclaration* XMLDocument::NewDeclaration( const char* str ) +{ + XMLDeclaration* dec = CreateUnlinkedNode( _commentPool ); + dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" ); + return dec; +} + + +XMLUnknown* XMLDocument::NewUnknown( const char* str ) +{ + XMLUnknown* unk = CreateUnlinkedNode( _commentPool ); + unk->SetValue( str ); + return unk; +} + +static FILE* callfopen( const char* filepath, const char* mode ) +{ + TIXMLASSERT( filepath ); + TIXMLASSERT( mode ); +#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE) + FILE* fp = 0; + const errno_t err = fopen_s( &fp, filepath, mode ); + if ( err ) { + return 0; + } +#else + FILE* fp = fopen( filepath, mode ); +#endif + return fp; +} + +void XMLDocument::DeleteNode( XMLNode* node ) { + TIXMLASSERT( node ); + TIXMLASSERT(node->_document == this ); + if (node->_parent) { + node->_parent->DeleteChild( node ); + } + else { + // Isn't in the tree. + // Use the parent delete. + // Also, we need to mark it tracked: we 'know' + // it was never used. + node->_memPool->SetTracked(); + // Call the static XMLNode version: + XMLNode::DeleteNode(node); + } +} + + +XMLError XMLDocument::LoadFile( const char* filename ) +{ + if ( !filename ) { + TIXMLASSERT( false ); + SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=" ); + return _errorID; + } + + Clear(); + FILE* fp = callfopen( filename, "rb" ); + if ( !fp ) { + SetError( XML_ERROR_FILE_NOT_FOUND, 0, "filename=%s", filename ); + return _errorID; + } + LoadFile( fp ); + fclose( fp ); + return _errorID; +} + +XMLError XMLDocument::LoadFile( FILE* fp ) +{ + Clear(); + + TIXML_FSEEK( fp, 0, SEEK_SET ); + if ( fgetc( fp ) == EOF && ferror( fp ) != 0 ) { + SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); + return _errorID; + } + + TIXML_FSEEK( fp, 0, SEEK_END ); + + unsigned long long filelength; + { + const long long fileLengthSigned = TIXML_FTELL( fp ); + TIXML_FSEEK( fp, 0, SEEK_SET ); + if ( fileLengthSigned == -1L ) { + SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); + return _errorID; + } + TIXMLASSERT( fileLengthSigned >= 0 ); + filelength = static_cast(fileLengthSigned); + } + + const size_t maxSizeT = static_cast(-1); + // We'll do the comparison as an unsigned long long, because that's guaranteed to be at + // least 8 bytes, even on a 32-bit platform. + if ( filelength >= static_cast(maxSizeT) ) { + // Cannot handle files which won't fit in buffer together with null terminator + SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); + return _errorID; + } + + if ( filelength == 0 ) { + SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); + return _errorID; + } + + const size_t size = static_cast(filelength); + TIXMLASSERT( _charBuffer == 0 ); + _charBuffer = new char[size+1]; + const size_t read = fread( _charBuffer, 1, size, fp ); + if ( read != size ) { + SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); + return _errorID; + } + + _charBuffer[size] = 0; + + Parse(); + return _errorID; +} + + +XMLError XMLDocument::SaveFile( const char* filename, bool compact ) +{ + if ( !filename ) { + TIXMLASSERT( false ); + SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=" ); + return _errorID; + } + + FILE* fp = callfopen( filename, "w" ); + if ( !fp ) { + SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=%s", filename ); + return _errorID; + } + SaveFile(fp, compact); + fclose( fp ); + return _errorID; +} + + +XMLError XMLDocument::SaveFile( FILE* fp, bool compact ) +{ + // Clear any error from the last save, otherwise it will get reported + // for *this* call. + ClearError(); + XMLPrinter stream( fp, compact ); + Print( &stream ); + return _errorID; +} + + +XMLError XMLDocument::Parse( const char* xml, size_t nBytes ) +{ + Clear(); + + if ( nBytes == 0 || !xml || !*xml ) { + SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); + return _errorID; + } + if ( nBytes == static_cast(-1) ) { + nBytes = strlen( xml ); + } + TIXMLASSERT( _charBuffer == 0 ); + _charBuffer = new char[ nBytes+1 ]; + memcpy( _charBuffer, xml, nBytes ); + _charBuffer[nBytes] = 0; + + Parse(); + if ( Error() ) { + // clean up now essentially dangling memory. + // and the parse fail can put objects in the + // pools that are dead and inaccessible. + DeleteChildren(); + _elementPool.Clear(); + _attributePool.Clear(); + _textPool.Clear(); + _commentPool.Clear(); + } + return _errorID; +} + + +void XMLDocument::Print( XMLPrinter* streamer ) const +{ + if ( streamer ) { + Accept( streamer ); + } + else { + XMLPrinter stdoutStreamer( stdout ); + Accept( &stdoutStreamer ); + } +} + + +void XMLDocument::ClearError() { + _errorID = XML_SUCCESS; + _errorLineNum = 0; + _errorStr.Reset(); +} + + +void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... ) +{ + TIXMLASSERT(error >= 0 && error < XML_ERROR_COUNT); + _errorID = error; + _errorLineNum = lineNum; + _errorStr.Reset(); + + const size_t BUFFER_SIZE = 1000; + char* buffer = new char[BUFFER_SIZE]; + + TIXMLASSERT(sizeof(error) <= sizeof(int)); + TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d (0x%x) Line number=%d", + ErrorIDToName(error), static_cast(error), static_cast(error), lineNum); + + if (format) { + size_t len = strlen(buffer); + TIXML_SNPRINTF(buffer + len, BUFFER_SIZE - len, ": "); + len = strlen(buffer); + + va_list va; + va_start(va, format); + TIXML_VSNPRINTF(buffer + len, BUFFER_SIZE - len, format, va); + va_end(va); + } + _errorStr.SetStr(buffer); + delete[] buffer; +} + + +/*static*/ const char* XMLDocument::ErrorIDToName(XMLError errorID) +{ + TIXMLASSERT( errorID >= 0 && errorID < XML_ERROR_COUNT ); + const char* errorName = _errorNames[errorID]; + TIXMLASSERT( errorName && errorName[0] ); + return errorName; +} + +const char* XMLDocument::ErrorStr() const +{ + return _errorStr.Empty() ? "" : _errorStr.GetStr(); +} + + +void XMLDocument::PrintError() const +{ + printf("%s\n", ErrorStr()); +} + +const char* XMLDocument::ErrorName() const +{ + return ErrorIDToName(_errorID); +} + +void XMLDocument::Parse() +{ + TIXMLASSERT( NoChildren() ); // Clear() must have been called previously + TIXMLASSERT( _charBuffer ); + _parseCurLineNum = 1; + _parseLineNum = 1; + char* p = _charBuffer; + p = XMLUtil::SkipWhiteSpace( p, &_parseCurLineNum ); + p = const_cast( XMLUtil::ReadBOM( p, &_writeBOM ) ); + if ( !*p ) { + SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); + return; + } + ParseDeep(p, 0, &_parseCurLineNum ); +} + +void XMLDocument::PushDepth() +{ + _parsingDepth++; + if (_parsingDepth == TINYXML2_MAX_ELEMENT_DEPTH) { + SetError(XML_ELEMENT_DEPTH_EXCEEDED, _parseCurLineNum, "Element nesting is too deep." ); + } +} + +void XMLDocument::PopDepth() +{ + TIXMLASSERT(_parsingDepth > 0); + --_parsingDepth; +} + +XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) : + _elementJustOpened( false ), + _stack(), + _firstElement( true ), + _fp( file ), + _depth( depth ), + _textDepth( -1 ), + _processEntities( true ), + _compactMode( compact ), + _buffer() +{ + for( int i=0; i(entityValue); + TIXMLASSERT( flagIndex < ENTITY_RANGE ); + _entityFlag[flagIndex] = true; + } + _restrictedEntityFlag[static_cast('&')] = true; + _restrictedEntityFlag[static_cast('<')] = true; + _restrictedEntityFlag[static_cast('>')] = true; // not required, but consistency is nice + _buffer.Push( 0 ); +} + + +void XMLPrinter::Print( const char* format, ... ) +{ + va_list va; + va_start( va, format ); + + if ( _fp ) { + vfprintf( _fp, format, va ); + } + else { + const int len = TIXML_VSCPRINTF( format, va ); + // Close out and re-start the va-args + va_end( va ); + TIXMLASSERT( len >= 0 ); + va_start( va, format ); + TIXMLASSERT( _buffer.Size() > 0 && _buffer[_buffer.Size() - 1] == 0 ); + char* p = _buffer.PushArr( len ) - 1; // back up over the null terminator. + TIXML_VSNPRINTF( p, len+1, format, va ); + } + va_end( va ); +} + + +void XMLPrinter::Write( const char* data, size_t size ) +{ + if ( _fp ) { + fwrite ( data , sizeof(char), size, _fp); + } + else { + char* p = _buffer.PushArr( static_cast(size) ) - 1; // back up over the null terminator. + memcpy( p, data, size ); + p[size] = 0; + } +} + + +void XMLPrinter::Putc( char ch ) +{ + if ( _fp ) { + fputc ( ch, _fp); + } + else { + char* p = _buffer.PushArr( sizeof(char) ) - 1; // back up over the null terminator. + p[0] = ch; + p[1] = 0; + } +} + + +void XMLPrinter::PrintSpace( int depth ) +{ + for( int i=0; i 0 && *q < ENTITY_RANGE ) { + // Check for entities. If one is found, flush + // the stream up until the entity, write the + // entity, and keep looking. + if ( flag[static_cast(*q)] ) { + while ( p < q ) { + const size_t delta = q - p; + const int toPrint = ( INT_MAX < delta ) ? INT_MAX : static_cast(delta); + Write( p, toPrint ); + p += toPrint; + } + bool entityPatternPrinted = false; + for( int i=0; i(delta); + Write( p, toPrint ); + } + } + else { + Write( p ); + } +} + + +void XMLPrinter::PushHeader( bool writeBOM, bool writeDec ) +{ + if ( writeBOM ) { + static const unsigned char bom[] = { TIXML_UTF_LEAD_0, TIXML_UTF_LEAD_1, TIXML_UTF_LEAD_2, 0 }; + Write( reinterpret_cast< const char* >( bom ) ); + } + if ( writeDec ) { + PushDeclaration( "xml version=\"1.0\"" ); + } +} + +void XMLPrinter::PrepareForNewNode( bool compactMode ) +{ + SealElementIfJustOpened(); + + if ( compactMode ) { + return; + } + + if ( _firstElement ) { + PrintSpace (_depth); + } else if ( _textDepth < 0) { + Putc( '\n' ); + PrintSpace( _depth ); + } + + _firstElement = false; +} + +void XMLPrinter::OpenElement( const char* name, bool compactMode ) +{ + PrepareForNewNode( compactMode ); + _stack.Push( name ); + + Write ( "<" ); + Write ( name ); + + _elementJustOpened = true; + ++_depth; +} + + +void XMLPrinter::PushAttribute( const char* name, const char* value ) +{ + TIXMLASSERT( _elementJustOpened ); + Putc ( ' ' ); + Write( name ); + Write( "=\"" ); + PrintString( value, false ); + Putc ( '\"' ); +} + + +void XMLPrinter::PushAttribute( const char* name, int v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + PushAttribute( name, buf ); +} + + +void XMLPrinter::PushAttribute( const char* name, unsigned v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + PushAttribute( name, buf ); +} + + +void XMLPrinter::PushAttribute(const char* name, int64_t v) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr(v, buf, BUF_SIZE); + PushAttribute(name, buf); +} + + +void XMLPrinter::PushAttribute(const char* name, uint64_t v) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr(v, buf, BUF_SIZE); + PushAttribute(name, buf); +} + + +void XMLPrinter::PushAttribute( const char* name, bool v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + PushAttribute( name, buf ); +} + + +void XMLPrinter::PushAttribute( const char* name, double v ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( v, buf, BUF_SIZE ); + PushAttribute( name, buf ); +} + + +void XMLPrinter::CloseElement( bool compactMode ) +{ + --_depth; + const char* name = _stack.Pop(); + + if ( _elementJustOpened ) { + Write( "/>" ); + } + else { + if ( _textDepth < 0 && !compactMode) { + Putc( '\n' ); + PrintSpace( _depth ); + } + Write ( "" ); + } + + if ( _textDepth == _depth ) { + _textDepth = -1; + } + if ( _depth == 0 && !compactMode) { + Putc( '\n' ); + } + _elementJustOpened = false; +} + + +void XMLPrinter::SealElementIfJustOpened() +{ + if ( !_elementJustOpened ) { + return; + } + _elementJustOpened = false; + Putc( '>' ); +} + + +void XMLPrinter::PushText( const char* text, bool cdata ) +{ + _textDepth = _depth-1; + + SealElementIfJustOpened(); + if ( cdata ) { + Write( "" ); + } + else { + PrintString( text, true ); + } +} + + +void XMLPrinter::PushText( int64_t value ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( value, buf, BUF_SIZE ); + PushText( buf, false ); +} + + +void XMLPrinter::PushText( uint64_t value ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr(value, buf, BUF_SIZE); + PushText(buf, false); +} + + +void XMLPrinter::PushText( int value ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( value, buf, BUF_SIZE ); + PushText( buf, false ); +} + + +void XMLPrinter::PushText( unsigned value ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( value, buf, BUF_SIZE ); + PushText( buf, false ); +} + + +void XMLPrinter::PushText( bool value ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( value, buf, BUF_SIZE ); + PushText( buf, false ); +} + + +void XMLPrinter::PushText( float value ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( value, buf, BUF_SIZE ); + PushText( buf, false ); +} + + +void XMLPrinter::PushText( double value ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( value, buf, BUF_SIZE ); + PushText( buf, false ); +} + + +void XMLPrinter::PushComment( const char* comment ) +{ + PrepareForNewNode( _compactMode ); + + Write( "" ); +} + + +void XMLPrinter::PushDeclaration( const char* value ) +{ + PrepareForNewNode( _compactMode ); + + Write( "" ); +} + + +void XMLPrinter::PushUnknown( const char* value ) +{ + PrepareForNewNode( _compactMode ); + + Write( "' ); +} + + +bool XMLPrinter::VisitEnter( const XMLDocument& doc ) +{ + _processEntities = doc.ProcessEntities(); + if ( doc.HasBOM() ) { + PushHeader( true, false ); + } + return true; +} + + +bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute ) +{ + const XMLElement* parentElem = 0; + if ( element.Parent() ) { + parentElem = element.Parent()->ToElement(); + } + const bool compactMode = parentElem ? CompactMode( *parentElem ) : _compactMode; + OpenElement( element.Name(), compactMode ); + while ( attribute ) { + PushAttribute( attribute->Name(), attribute->Value() ); + attribute = attribute->Next(); + } + return true; +} + + +bool XMLPrinter::VisitExit( const XMLElement& element ) +{ + CloseElement( CompactMode(element) ); + return true; +} + + +bool XMLPrinter::Visit( const XMLText& text ) +{ + PushText( text.Value(), text.CData() ); + return true; +} + + +bool XMLPrinter::Visit( const XMLComment& comment ) +{ + PushComment( comment.Value() ); + return true; +} + +bool XMLPrinter::Visit( const XMLDeclaration& declaration ) +{ + PushDeclaration( declaration.Value() ); + return true; +} + + +bool XMLPrinter::Visit( const XMLUnknown& unknown ) +{ + PushUnknown( unknown.Value() ); + return true; +} + +} // namespace tinyxml2 diff --git a/third_party/tinyxml2/tinyxml2.h b/third_party/tinyxml2/tinyxml2.h new file mode 100644 index 0000000..9626be8 --- /dev/null +++ b/third_party/tinyxml2/tinyxml2.h @@ -0,0 +1,2383 @@ +/* +Original code by Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#ifndef TINYXML2_INCLUDED +#define TINYXML2_INCLUDED + +#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__) +# include +# include +# include +# include +# include +# if defined(__PS3__) +# include +# endif +#else +# include +# include +# include +# include +# include +#endif +#include + +/* + gcc: + g++ -Wall -DTINYXML2_DEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe + + Formatting, Artistic Style: + AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h +*/ + +#if defined( _DEBUG ) || defined (__DEBUG__) +# ifndef TINYXML2_DEBUG +# define TINYXML2_DEBUG +# endif +#endif + +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable: 4251) +#endif + +#ifdef _MSC_VER +# ifdef TINYXML2_EXPORT +# define TINYXML2_LIB __declspec(dllexport) +# elif defined(TINYXML2_IMPORT) +# define TINYXML2_LIB __declspec(dllimport) +# else +# define TINYXML2_LIB +# endif +#elif __GNUC__ >= 4 +# define TINYXML2_LIB __attribute__((visibility("default"))) +#else +# define TINYXML2_LIB +#endif + + +#if !defined(TIXMLASSERT) +#if defined(TINYXML2_DEBUG) +# if defined(_MSC_VER) +# // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like +# define TIXMLASSERT( x ) do { if ( !((void)0,(x))) { __debugbreak(); } } while(false) +# elif defined (ANDROID_NDK) +# include +# define TIXMLASSERT( x ) do { if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); } } while(false) +# else +# include +# define TIXMLASSERT assert +# endif +#else +# define TIXMLASSERT( x ) do {} while(false) +#endif +#endif + +/* Versioning, past 1.0.14: + http://semver.org/ +*/ +static const int TIXML2_MAJOR_VERSION = 11; +static const int TIXML2_MINOR_VERSION = 0; +static const int TIXML2_PATCH_VERSION = 0; + +#define TINYXML2_MAJOR_VERSION 11 +#define TINYXML2_MINOR_VERSION 0 +#define TINYXML2_PATCH_VERSION 0 + +// A fixed element depth limit is problematic. There needs to be a +// limit to avoid a stack overflow. However, that limit varies per +// system, and the capacity of the stack. On the other hand, it's a trivial +// attack that can result from ill, malicious, or even correctly formed XML, +// so there needs to be a limit in place. +static const int TINYXML2_MAX_ELEMENT_DEPTH = 500; + +namespace tinyxml2 +{ +class XMLDocument; +class XMLElement; +class XMLAttribute; +class XMLComment; +class XMLText; +class XMLDeclaration; +class XMLUnknown; +class XMLPrinter; + +/* + A class that wraps strings. Normally stores the start and end + pointers into the XML file itself, and will apply normalization + and entity translation if actually read. Can also store (and memory + manage) a traditional char[] + + Isn't clear why TINYXML2_LIB is needed; but seems to fix #719 +*/ +class TINYXML2_LIB StrPair +{ +public: + enum Mode { + NEEDS_ENTITY_PROCESSING = 0x01, + NEEDS_NEWLINE_NORMALIZATION = 0x02, + NEEDS_WHITESPACE_COLLAPSING = 0x04, + + TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, + TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, + ATTRIBUTE_NAME = 0, + ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, + ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, + COMMENT = NEEDS_NEWLINE_NORMALIZATION + }; + + StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {} + ~StrPair(); + + void Set( char* start, char* end, int flags ) { + TIXMLASSERT( start ); + TIXMLASSERT( end ); + Reset(); + _start = start; + _end = end; + _flags = flags | NEEDS_FLUSH; + } + + const char* GetStr(); + + bool Empty() const { + return _start == _end; + } + + void SetInternedStr( const char* str ) { + Reset(); + _start = const_cast(str); + } + + void SetStr( const char* str, int flags=0 ); + + char* ParseText( char* in, const char* endTag, int strFlags, int* curLineNumPtr ); + char* ParseName( char* in ); + + void TransferTo( StrPair* other ); + void Reset(); + +private: + void CollapseWhitespace(); + + enum { + NEEDS_FLUSH = 0x100, + NEEDS_DELETE = 0x200 + }; + + int _flags; + char* _start; + char* _end; + + StrPair( const StrPair& other ); // not supported + void operator=( const StrPair& other ); // not supported, use TransferTo() +}; + + +/* + A dynamic array of Plain Old Data. Doesn't support constructors, etc. + Has a small initial memory pool, so that low or no usage will not + cause a call to new/delete +*/ +template +class DynArray +{ +public: + DynArray() : + _mem( _pool ), + _allocated( INITIAL_SIZE ), + _size( 0 ) + { + } + + ~DynArray() { + if ( _mem != _pool ) { + delete [] _mem; + } + } + + void Clear() { + _size = 0; + } + + void Push( T t ) { + TIXMLASSERT( _size < INT_MAX ); + EnsureCapacity( _size+1 ); + _mem[_size] = t; + ++_size; + } + + T* PushArr( size_t count ) { + TIXMLASSERT( _size <= SIZE_MAX - count ); + EnsureCapacity( _size+count ); + T* ret = &_mem[_size]; + _size += count; + return ret; + } + + T Pop() { + TIXMLASSERT( _size > 0 ); + --_size; + return _mem[_size]; + } + + void PopArr( size_t count ) { + TIXMLASSERT( _size >= count ); + _size -= count; + } + + bool Empty() const { + return _size == 0; + } + + T& operator[](size_t i) { + TIXMLASSERT( i < _size ); + return _mem[i]; + } + + const T& operator[](size_t i) const { + TIXMLASSERT( i < _size ); + return _mem[i]; + } + + const T& PeekTop() const { + TIXMLASSERT( _size > 0 ); + return _mem[ _size - 1]; + } + + size_t Size() const { + TIXMLASSERT( _size >= 0 ); + return _size; + } + + size_t Capacity() const { + TIXMLASSERT( _allocated >= INITIAL_SIZE ); + return _allocated; + } + + void SwapRemove(size_t i) { + TIXMLASSERT(i < _size); + TIXMLASSERT(_size > 0); + _mem[i] = _mem[_size - 1]; + --_size; + } + + const T* Mem() const { + TIXMLASSERT( _mem ); + return _mem; + } + + T* Mem() { + TIXMLASSERT( _mem ); + return _mem; + } + +private: + DynArray( const DynArray& ); // not supported + void operator=( const DynArray& ); // not supported + + void EnsureCapacity( size_t cap ) { + TIXMLASSERT( cap > 0 ); + if ( cap > _allocated ) { + TIXMLASSERT( cap <= SIZE_MAX / 2 / sizeof(T)); + const size_t newAllocated = cap * 2; + T* newMem = new T[newAllocated]; + TIXMLASSERT( newAllocated >= _size ); + memcpy( newMem, _mem, sizeof(T) * _size ); // warning: not using constructors, only works for PODs + if ( _mem != _pool ) { + delete [] _mem; + } + _mem = newMem; + _allocated = newAllocated; + } + } + + T* _mem; + T _pool[INITIAL_SIZE]; + size_t _allocated; // objects allocated + size_t _size; // number objects in use +}; + + +/* + Parent virtual class of a pool for fast allocation + and deallocation of objects. +*/ +class MemPool +{ +public: + MemPool() {} + virtual ~MemPool() {} + + virtual size_t ItemSize() const = 0; + virtual void* Alloc() = 0; + virtual void Free( void* ) = 0; + virtual void SetTracked() = 0; +}; + + +/* + Template child class to create pools of the correct type. +*/ +template< size_t ITEM_SIZE > +class MemPoolT : public MemPool +{ +public: + MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} + ~MemPoolT() { + MemPoolT< ITEM_SIZE >::Clear(); + } + + void Clear() { + // Delete the blocks. + while( !_blockPtrs.Empty()) { + Block* lastBlock = _blockPtrs.Pop(); + delete lastBlock; + } + _root = 0; + _currentAllocs = 0; + _nAllocs = 0; + _maxAllocs = 0; + _nUntracked = 0; + } + + virtual size_t ItemSize() const override { + return ITEM_SIZE; + } + size_t CurrentAllocs() const { + return _currentAllocs; + } + + virtual void* Alloc() override{ + if ( !_root ) { + // Need a new block. + Block* block = new Block; + _blockPtrs.Push( block ); + + Item* blockItems = block->items; + for( size_t i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) { + blockItems[i].next = &(blockItems[i + 1]); + } + blockItems[ITEMS_PER_BLOCK - 1].next = 0; + _root = blockItems; + } + Item* const result = _root; + TIXMLASSERT( result != 0 ); + _root = _root->next; + + ++_currentAllocs; + if ( _currentAllocs > _maxAllocs ) { + _maxAllocs = _currentAllocs; + } + ++_nAllocs; + ++_nUntracked; + return result; + } + + virtual void Free( void* mem ) override { + if ( !mem ) { + return; + } + --_currentAllocs; + Item* item = static_cast( mem ); +#ifdef TINYXML2_DEBUG + memset( item, 0xfe, sizeof( *item ) ); +#endif + item->next = _root; + _root = item; + } + void Trace( const char* name ) { + printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n", + name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs, + ITEM_SIZE, _nAllocs, _blockPtrs.Size() ); + } + + void SetTracked() override { + --_nUntracked; + } + + size_t Untracked() const { + return _nUntracked; + } + + // This number is perf sensitive. 4k seems like a good tradeoff on my machine. + // The test file is large, 170k. + // Release: VS2010 gcc(no opt) + // 1k: 4000 + // 2k: 4000 + // 4k: 3900 21000 + // 16k: 5200 + // 32k: 4300 + // 64k: 4000 21000 + // Declared public because some compilers do not accept to use ITEMS_PER_BLOCK + // in private part if ITEMS_PER_BLOCK is private + enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE }; + +private: + MemPoolT( const MemPoolT& ); // not supported + void operator=( const MemPoolT& ); // not supported + + union Item { + Item* next; + char itemData[static_cast(ITEM_SIZE)]; + }; + struct Block { + Item items[ITEMS_PER_BLOCK]; + }; + DynArray< Block*, 10 > _blockPtrs; + Item* _root; + + size_t _currentAllocs; + size_t _nAllocs; + size_t _maxAllocs; + size_t _nUntracked; +}; + + + +/** + Implements the interface to the "Visitor pattern" (see the Accept() method.) + If you call the Accept() method, it requires being passed a XMLVisitor + class to handle callbacks. For nodes that contain other nodes (Document, Element) + you will get called with a VisitEnter/VisitExit pair. Nodes that are always leafs + are simply called with Visit(). + + If you return 'true' from a Visit method, recursive parsing will continue. If you return + false, no children of this node or its siblings will be visited. + + All flavors of Visit methods have a default implementation that returns 'true' (continue + visiting). You need to only override methods that are interesting to you. + + Generally Accept() is called on the XMLDocument, although all nodes support visiting. + + You should never change the document from a callback. + + @sa XMLNode::Accept() +*/ +class TINYXML2_LIB XMLVisitor +{ +public: + virtual ~XMLVisitor() {} + + /// Visit a document. + virtual bool VisitEnter( const XMLDocument& /*doc*/ ) { + return true; + } + /// Visit a document. + virtual bool VisitExit( const XMLDocument& /*doc*/ ) { + return true; + } + + /// Visit an element. + virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) { + return true; + } + /// Visit an element. + virtual bool VisitExit( const XMLElement& /*element*/ ) { + return true; + } + + /// Visit a declaration. + virtual bool Visit( const XMLDeclaration& /*declaration*/ ) { + return true; + } + /// Visit a text node. + virtual bool Visit( const XMLText& /*text*/ ) { + return true; + } + /// Visit a comment node. + virtual bool Visit( const XMLComment& /*comment*/ ) { + return true; + } + /// Visit an unknown node. + virtual bool Visit( const XMLUnknown& /*unknown*/ ) { + return true; + } +}; + +// WARNING: must match XMLDocument::_errorNames[] +enum XMLError { + XML_SUCCESS = 0, + XML_NO_ATTRIBUTE, + XML_WRONG_ATTRIBUTE_TYPE, + XML_ERROR_FILE_NOT_FOUND, + XML_ERROR_FILE_COULD_NOT_BE_OPENED, + XML_ERROR_FILE_READ_ERROR, + XML_ERROR_PARSING_ELEMENT, + XML_ERROR_PARSING_ATTRIBUTE, + XML_ERROR_PARSING_TEXT, + XML_ERROR_PARSING_CDATA, + XML_ERROR_PARSING_COMMENT, + XML_ERROR_PARSING_DECLARATION, + XML_ERROR_PARSING_UNKNOWN, + XML_ERROR_EMPTY_DOCUMENT, + XML_ERROR_MISMATCHED_ELEMENT, + XML_ERROR_PARSING, + XML_CAN_NOT_CONVERT_TEXT, + XML_NO_TEXT_NODE, + XML_ELEMENT_DEPTH_EXCEEDED, + + XML_ERROR_COUNT +}; + + +/* + Utility functionality. +*/ +class TINYXML2_LIB XMLUtil +{ +public: + static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) { + TIXMLASSERT( p ); + + while( IsWhiteSpace(*p) ) { + if (curLineNumPtr && *p == '\n') { + ++(*curLineNumPtr); + } + ++p; + } + TIXMLASSERT( p ); + return p; + } + static char* SkipWhiteSpace( char* const p, int* curLineNumPtr ) { + return const_cast( SkipWhiteSpace( const_cast(p), curLineNumPtr ) ); + } + + // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't + // correct, but simple, and usually works. + static bool IsWhiteSpace( char p ) { + return !IsUTF8Continuation(p) && isspace( static_cast(p) ); + } + + inline static bool IsNameStartChar( unsigned char ch ) { + if ( ch >= 128 ) { + // This is a heuristic guess in attempt to not implement Unicode-aware isalpha() + return true; + } + if ( isalpha( ch ) ) { + return true; + } + return ch == ':' || ch == '_'; + } + + inline static bool IsNameChar( unsigned char ch ) { + return IsNameStartChar( ch ) + || isdigit( ch ) + || ch == '.' + || ch == '-'; + } + + inline static bool IsPrefixHex( const char* p) { + p = SkipWhiteSpace(p, 0); + return p && *p == '0' && ( *(p + 1) == 'x' || *(p + 1) == 'X'); + } + + inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) { + if ( p == q ) { + return true; + } + TIXMLASSERT( p ); + TIXMLASSERT( q ); + TIXMLASSERT( nChar >= 0 ); + return strncmp( p, q, static_cast(nChar) ) == 0; + } + + inline static bool IsUTF8Continuation( const char p ) { + return ( p & 0x80 ) != 0; + } + + static const char* ReadBOM( const char* p, bool* hasBOM ); + // p is the starting location, + // the UTF-8 value of the entity will be placed in value, and length filled in. + static const char* GetCharacterRef( const char* p, char* value, int* length ); + static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ); + + // converts primitive types to strings + static void ToStr( int v, char* buffer, int bufferSize ); + static void ToStr( unsigned v, char* buffer, int bufferSize ); + static void ToStr( bool v, char* buffer, int bufferSize ); + static void ToStr( float v, char* buffer, int bufferSize ); + static void ToStr( double v, char* buffer, int bufferSize ); + static void ToStr(int64_t v, char* buffer, int bufferSize); + static void ToStr(uint64_t v, char* buffer, int bufferSize); + + // converts strings to primitive types + static bool ToInt( const char* str, int* value ); + static bool ToUnsigned( const char* str, unsigned* value ); + static bool ToBool( const char* str, bool* value ); + static bool ToFloat( const char* str, float* value ); + static bool ToDouble( const char* str, double* value ); + static bool ToInt64(const char* str, int64_t* value); + static bool ToUnsigned64(const char* str, uint64_t* value); + // Changes what is serialized for a boolean value. + // Default to "true" and "false". Shouldn't be changed + // unless you have a special testing or compatibility need. + // Be careful: static, global, & not thread safe. + // Be sure to set static const memory as parameters. + static void SetBoolSerialization(const char* writeTrue, const char* writeFalse); + +private: + static const char* writeBoolTrue; + static const char* writeBoolFalse; +}; + + +/** XMLNode is a base class for every object that is in the + XML Document Object Model (DOM), except XMLAttributes. + Nodes have siblings, a parent, and children which can + be navigated. A node is always in a XMLDocument. + The type of a XMLNode can be queried, and it can + be cast to its more defined type. + + A XMLDocument allocates memory for all its Nodes. + When the XMLDocument gets deleted, all its Nodes + will also be deleted. + + @verbatim + A Document can contain: Element (container or leaf) + Comment (leaf) + Unknown (leaf) + Declaration( leaf ) + + An Element can contain: Element (container or leaf) + Text (leaf) + Attributes (not on tree) + Comment (leaf) + Unknown (leaf) + + @endverbatim +*/ +class TINYXML2_LIB XMLNode +{ + friend class XMLDocument; + friend class XMLElement; +public: + + /// Get the XMLDocument that owns this XMLNode. + const XMLDocument* GetDocument() const { + TIXMLASSERT( _document ); + return _document; + } + /// Get the XMLDocument that owns this XMLNode. + XMLDocument* GetDocument() { + TIXMLASSERT( _document ); + return _document; + } + + /// Safely cast to an Element, or null. + virtual XMLElement* ToElement() { + return 0; + } + /// Safely cast to Text, or null. + virtual XMLText* ToText() { + return 0; + } + /// Safely cast to a Comment, or null. + virtual XMLComment* ToComment() { + return 0; + } + /// Safely cast to a Document, or null. + virtual XMLDocument* ToDocument() { + return 0; + } + /// Safely cast to a Declaration, or null. + virtual XMLDeclaration* ToDeclaration() { + return 0; + } + /// Safely cast to an Unknown, or null. + virtual XMLUnknown* ToUnknown() { + return 0; + } + + virtual const XMLElement* ToElement() const { + return 0; + } + virtual const XMLText* ToText() const { + return 0; + } + virtual const XMLComment* ToComment() const { + return 0; + } + virtual const XMLDocument* ToDocument() const { + return 0; + } + virtual const XMLDeclaration* ToDeclaration() const { + return 0; + } + virtual const XMLUnknown* ToUnknown() const { + return 0; + } + + // ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2. + + int ChildElementCount(const char *value) const; + + int ChildElementCount() const; + + /** The meaning of 'value' changes for the specific type. + @verbatim + Document: empty (NULL is returned, not an empty string) + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text string + @endverbatim + */ + const char* Value() const; + + /** Set the Value of an XML node. + @sa Value() + */ + void SetValue( const char* val, bool staticMem=false ); + + /// Gets the line number the node is in, if the document was parsed from a file. + int GetLineNum() const { return _parseLineNum; } + + /// Get the parent of this node on the DOM. + const XMLNode* Parent() const { + return _parent; + } + + XMLNode* Parent() { + return _parent; + } + + /// Returns true if this node has no children. + bool NoChildren() const { + return !_firstChild; + } + + /// Get the first child node, or null if none exists. + const XMLNode* FirstChild() const { + return _firstChild; + } + + XMLNode* FirstChild() { + return _firstChild; + } + + /** Get the first child element, or optionally the first child + element with the specified name. + */ + const XMLElement* FirstChildElement( const char* name = 0 ) const; + + XMLElement* FirstChildElement( const char* name = 0 ) { + return const_cast(const_cast(this)->FirstChildElement( name )); + } + + /// Get the last child node, or null if none exists. + const XMLNode* LastChild() const { + return _lastChild; + } + + XMLNode* LastChild() { + return _lastChild; + } + + /** Get the last child element or optionally the last child + element with the specified name. + */ + const XMLElement* LastChildElement( const char* name = 0 ) const; + + XMLElement* LastChildElement( const char* name = 0 ) { + return const_cast(const_cast(this)->LastChildElement(name) ); + } + + /// Get the previous (left) sibling node of this node. + const XMLNode* PreviousSibling() const { + return _prev; + } + + XMLNode* PreviousSibling() { + return _prev; + } + + /// Get the previous (left) sibling element of this node, with an optionally supplied name. + const XMLElement* PreviousSiblingElement( const char* name = 0 ) const ; + + XMLElement* PreviousSiblingElement( const char* name = 0 ) { + return const_cast(const_cast(this)->PreviousSiblingElement( name ) ); + } + + /// Get the next (right) sibling node of this node. + const XMLNode* NextSibling() const { + return _next; + } + + XMLNode* NextSibling() { + return _next; + } + + /// Get the next (right) sibling element of this node, with an optionally supplied name. + const XMLElement* NextSiblingElement( const char* name = 0 ) const; + + XMLElement* NextSiblingElement( const char* name = 0 ) { + return const_cast(const_cast(this)->NextSiblingElement( name ) ); + } + + /** + Add a child node as the last (right) child. + If the child node is already part of the document, + it is moved from its old location to the new location. + Returns the addThis argument or 0 if the node does not + belong to the same document. + */ + XMLNode* InsertEndChild( XMLNode* addThis ); + + XMLNode* LinkEndChild( XMLNode* addThis ) { + return InsertEndChild( addThis ); + } + /** + Add a child node as the first (left) child. + If the child node is already part of the document, + it is moved from its old location to the new location. + Returns the addThis argument or 0 if the node does not + belong to the same document. + */ + XMLNode* InsertFirstChild( XMLNode* addThis ); + /** + Add a node after the specified child node. + If the child node is already part of the document, + it is moved from its old location to the new location. + Returns the addThis argument or 0 if the afterThis node + is not a child of this node, or if the node does not + belong to the same document. + */ + XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ); + + /** + Delete all the children of this node. + */ + void DeleteChildren(); + + /** + Delete a child of this node. + */ + void DeleteChild( XMLNode* node ); + + /** + Make a copy of this node, but not its children. + You may pass in a Document pointer that will be + the owner of the new Node. If the 'document' is + null, then the node returned will be allocated + from the current Document. (this->GetDocument()) + + Note: if called on a XMLDocument, this will return null. + */ + virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0; + + /** + Make a copy of this node and all its children. + + If the 'target' is null, then the nodes will + be allocated in the current document. If 'target' + is specified, the memory will be allocated in the + specified XMLDocument. + + NOTE: This is probably not the correct tool to + copy a document, since XMLDocuments can have multiple + top level XMLNodes. You probably want to use + XMLDocument::DeepCopy() + */ + XMLNode* DeepClone( XMLDocument* target ) const; + + /** + Test if 2 nodes are the same, but don't test children. + The 2 nodes do not need to be in the same Document. + + Note: if called on a XMLDocument, this will return false. + */ + virtual bool ShallowEqual( const XMLNode* compare ) const = 0; + + /** Accept a hierarchical visit of the nodes in the TinyXML-2 DOM. Every node in the + XML tree will be conditionally visited and the host will be called back + via the XMLVisitor interface. + + This is essentially a SAX interface for TinyXML-2. (Note however it doesn't re-parse + the XML for the callbacks, so the performance of TinyXML-2 is unchanged by using this + interface versus any other.) + + The interface has been based on ideas from: + + - http://www.saxproject.org/ + - http://c2.com/cgi/wiki?HierarchicalVisitorPattern + + Which are both good references for "visiting". + + An example of using Accept(): + @verbatim + XMLPrinter printer; + tinyxmlDoc.Accept( &printer ); + const char* xmlcstr = printer.CStr(); + @endverbatim + */ + virtual bool Accept( XMLVisitor* visitor ) const = 0; + + /** + Set user data into the XMLNode. TinyXML-2 in + no way processes or interprets user data. + It is initially 0. + */ + void SetUserData(void* userData) { _userData = userData; } + + /** + Get user data set into the XMLNode. TinyXML-2 in + no way processes or interprets user data. + It is initially 0. + */ + void* GetUserData() const { return _userData; } + +protected: + explicit XMLNode( XMLDocument* ); + virtual ~XMLNode(); + + virtual char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr); + + XMLDocument* _document; + XMLNode* _parent; + mutable StrPair _value; + int _parseLineNum; + + XMLNode* _firstChild; + XMLNode* _lastChild; + + XMLNode* _prev; + XMLNode* _next; + + void* _userData; + +private: + MemPool* _memPool; + void Unlink( XMLNode* child ); + static void DeleteNode( XMLNode* node ); + void InsertChildPreamble( XMLNode* insertThis ) const; + const XMLElement* ToElementWithName( const char* name ) const; + + XMLNode( const XMLNode& ); // not supported + XMLNode& operator=( const XMLNode& ); // not supported +}; + + +/** XML text. + + Note that a text node can have child element nodes, for example: + @verbatim + This is bold + @endverbatim + + A text node can have 2 ways to output the next. "normal" output + and CDATA. It will default to the mode it was parsed from the XML file and + you generally want to leave it alone, but you can change the output mode with + SetCData() and query it with CData(). +*/ +class TINYXML2_LIB XMLText : public XMLNode +{ + friend class XMLDocument; +public: + virtual bool Accept( XMLVisitor* visitor ) const override; + + virtual XMLText* ToText() override { + return this; + } + virtual const XMLText* ToText() const override { + return this; + } + + /// Declare whether this should be CDATA or standard text. + void SetCData( bool isCData ) { + _isCData = isCData; + } + /// Returns true if this is a CDATA text element. + bool CData() const { + return _isCData; + } + + virtual XMLNode* ShallowClone( XMLDocument* document ) const override; + virtual bool ShallowEqual( const XMLNode* compare ) const override; + +protected: + explicit XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {} + virtual ~XMLText() {} + + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override; + +private: + bool _isCData; + + XMLText( const XMLText& ); // not supported + XMLText& operator=( const XMLText& ); // not supported +}; + + +/** An XML Comment. */ +class TINYXML2_LIB XMLComment : public XMLNode +{ + friend class XMLDocument; +public: + virtual XMLComment* ToComment() override { + return this; + } + virtual const XMLComment* ToComment() const override { + return this; + } + + virtual bool Accept( XMLVisitor* visitor ) const override; + + virtual XMLNode* ShallowClone( XMLDocument* document ) const override; + virtual bool ShallowEqual( const XMLNode* compare ) const override; + +protected: + explicit XMLComment( XMLDocument* doc ); + virtual ~XMLComment(); + + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr) override; + +private: + XMLComment( const XMLComment& ); // not supported + XMLComment& operator=( const XMLComment& ); // not supported +}; + + +/** In correct XML the declaration is the first entry in the file. + @verbatim + + @endverbatim + + TinyXML-2 will happily read or write files without a declaration, + however. + + The text of the declaration isn't interpreted. It is parsed + and written as a string. +*/ +class TINYXML2_LIB XMLDeclaration : public XMLNode +{ + friend class XMLDocument; +public: + virtual XMLDeclaration* ToDeclaration() override { + return this; + } + virtual const XMLDeclaration* ToDeclaration() const override { + return this; + } + + virtual bool Accept( XMLVisitor* visitor ) const override; + + virtual XMLNode* ShallowClone( XMLDocument* document ) const override; + virtual bool ShallowEqual( const XMLNode* compare ) const override; + +protected: + explicit XMLDeclaration( XMLDocument* doc ); + virtual ~XMLDeclaration(); + + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override; + +private: + XMLDeclaration( const XMLDeclaration& ); // not supported + XMLDeclaration& operator=( const XMLDeclaration& ); // not supported +}; + + +/** Any tag that TinyXML-2 doesn't recognize is saved as an + unknown. It is a tag of text, but should not be modified. + It will be written back to the XML, unchanged, when the file + is saved. + + DTD tags get thrown into XMLUnknowns. +*/ +class TINYXML2_LIB XMLUnknown : public XMLNode +{ + friend class XMLDocument; +public: + virtual XMLUnknown* ToUnknown() override { + return this; + } + virtual const XMLUnknown* ToUnknown() const override { + return this; + } + + virtual bool Accept( XMLVisitor* visitor ) const override; + + virtual XMLNode* ShallowClone( XMLDocument* document ) const override; + virtual bool ShallowEqual( const XMLNode* compare ) const override; + +protected: + explicit XMLUnknown( XMLDocument* doc ); + virtual ~XMLUnknown(); + + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override; + +private: + XMLUnknown( const XMLUnknown& ); // not supported + XMLUnknown& operator=( const XMLUnknown& ); // not supported +}; + + + +/** An attribute is a name-value pair. Elements have an arbitrary + number of attributes, each with a unique name. + + @note The attributes are not XMLNodes. You may only query the + Next() attribute in a list. +*/ +class TINYXML2_LIB XMLAttribute +{ + friend class XMLElement; +public: + /// The name of the attribute. + const char* Name() const; + + /// The value of the attribute. + const char* Value() const; + + /// Gets the line number the attribute is in, if the document was parsed from a file. + int GetLineNum() const { return _parseLineNum; } + + /// The next attribute in the list. + const XMLAttribute* Next() const { + return _next; + } + + /** IntValue interprets the attribute as an integer, and returns the value. + If the value isn't an integer, 0 will be returned. There is no error checking; + use QueryIntValue() if you need error checking. + */ + int IntValue() const { + int i = 0; + QueryIntValue(&i); + return i; + } + + int64_t Int64Value() const { + int64_t i = 0; + QueryInt64Value(&i); + return i; + } + + uint64_t Unsigned64Value() const { + uint64_t i = 0; + QueryUnsigned64Value(&i); + return i; + } + + /// Query as an unsigned integer. See IntValue() + unsigned UnsignedValue() const { + unsigned i=0; + QueryUnsignedValue( &i ); + return i; + } + /// Query as a boolean. See IntValue() + bool BoolValue() const { + bool b=false; + QueryBoolValue( &b ); + return b; + } + /// Query as a double. See IntValue() + double DoubleValue() const { + double d=0; + QueryDoubleValue( &d ); + return d; + } + /// Query as a float. See IntValue() + float FloatValue() const { + float f=0; + QueryFloatValue( &f ); + return f; + } + + /** QueryIntValue interprets the attribute as an integer, and returns the value + in the provided parameter. The function will return XML_SUCCESS on success, + and XML_WRONG_ATTRIBUTE_TYPE if the conversion is not successful. + */ + XMLError QueryIntValue( int* value ) const; + /// See QueryIntValue + XMLError QueryUnsignedValue( unsigned int* value ) const; + /// See QueryIntValue + XMLError QueryInt64Value(int64_t* value) const; + /// See QueryIntValue + XMLError QueryUnsigned64Value(uint64_t* value) const; + /// See QueryIntValue + XMLError QueryBoolValue( bool* value ) const; + /// See QueryIntValue + XMLError QueryDoubleValue( double* value ) const; + /// See QueryIntValue + XMLError QueryFloatValue( float* value ) const; + + /// Set the attribute to a string value. + void SetAttribute( const char* value ); + /// Set the attribute to value. + void SetAttribute( int value ); + /// Set the attribute to value. + void SetAttribute( unsigned value ); + /// Set the attribute to value. + void SetAttribute(int64_t value); + /// Set the attribute to value. + void SetAttribute(uint64_t value); + /// Set the attribute to value. + void SetAttribute( bool value ); + /// Set the attribute to value. + void SetAttribute( double value ); + /// Set the attribute to value. + void SetAttribute( float value ); + +private: + enum { BUF_SIZE = 200 }; + + XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {} + virtual ~XMLAttribute() {} + + XMLAttribute( const XMLAttribute& ); // not supported + void operator=( const XMLAttribute& ); // not supported + void SetName( const char* name ); + + char* ParseDeep( char* p, bool processEntities, int* curLineNumPtr ); + + mutable StrPair _name; + mutable StrPair _value; + int _parseLineNum; + XMLAttribute* _next; + MemPool* _memPool; +}; + + +/** The element is a container class. It has a value, the element name, + and can contain other elements, text, comments, and unknowns. + Elements also contain an arbitrary number of attributes. +*/ +class TINYXML2_LIB XMLElement : public XMLNode +{ + friend class XMLDocument; +public: + /// Get the name of an element (which is the Value() of the node.) + const char* Name() const { + return Value(); + } + /// Set the name of the element. + void SetName( const char* str, bool staticMem=false ) { + SetValue( str, staticMem ); + } + + virtual XMLElement* ToElement() override { + return this; + } + virtual const XMLElement* ToElement() const override { + return this; + } + virtual bool Accept( XMLVisitor* visitor ) const override; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none + exists. For example: + + @verbatim + const char* value = ele->Attribute( "foo" ); + @endverbatim + + The 'value' parameter is normally null. However, if specified, + the attribute will only be returned if the 'name' and 'value' + match. This allow you to write code: + + @verbatim + if ( ele->Attribute( "foo", "bar" ) ) callFooIsBar(); + @endverbatim + + rather than: + @verbatim + if ( ele->Attribute( "foo" ) ) { + if ( strcmp( ele->Attribute( "foo" ), "bar" ) == 0 ) callFooIsBar(); + } + @endverbatim + */ + const char* Attribute( const char* name, const char* value=0 ) const; + + /** Given an attribute name, IntAttribute() returns the value + of the attribute interpreted as an integer. The default + value will be returned if the attribute isn't present, + or if there is an error. (For a method with error + checking, see QueryIntAttribute()). + */ + int IntAttribute(const char* name, int defaultValue = 0) const; + /// See IntAttribute() + unsigned UnsignedAttribute(const char* name, unsigned defaultValue = 0) const; + /// See IntAttribute() + int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const; + /// See IntAttribute() + uint64_t Unsigned64Attribute(const char* name, uint64_t defaultValue = 0) const; + /// See IntAttribute() + bool BoolAttribute(const char* name, bool defaultValue = false) const; + /// See IntAttribute() + double DoubleAttribute(const char* name, double defaultValue = 0) const; + /// See IntAttribute() + float FloatAttribute(const char* name, float defaultValue = 0) const; + + /** Given an attribute name, QueryIntAttribute() returns + XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion + can't be performed, or XML_NO_ATTRIBUTE if the attribute + doesn't exist. If successful, the result of the conversion + will be written to 'value'. If not successful, nothing will + be written to 'value'. This allows you to provide default + value: + + @verbatim + int value = 10; + QueryIntAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 + @endverbatim + */ + XMLError QueryIntAttribute( const char* name, int* value ) const { + const XMLAttribute* a = FindAttribute( name ); + if ( !a ) { + return XML_NO_ATTRIBUTE; + } + return a->QueryIntValue( value ); + } + + /// See QueryIntAttribute() + XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const { + const XMLAttribute* a = FindAttribute( name ); + if ( !a ) { + return XML_NO_ATTRIBUTE; + } + return a->QueryUnsignedValue( value ); + } + + /// See QueryIntAttribute() + XMLError QueryInt64Attribute(const char* name, int64_t* value) const { + const XMLAttribute* a = FindAttribute(name); + if (!a) { + return XML_NO_ATTRIBUTE; + } + return a->QueryInt64Value(value); + } + + /// See QueryIntAttribute() + XMLError QueryUnsigned64Attribute(const char* name, uint64_t* value) const { + const XMLAttribute* a = FindAttribute(name); + if(!a) { + return XML_NO_ATTRIBUTE; + } + return a->QueryUnsigned64Value(value); + } + + /// See QueryIntAttribute() + XMLError QueryBoolAttribute( const char* name, bool* value ) const { + const XMLAttribute* a = FindAttribute( name ); + if ( !a ) { + return XML_NO_ATTRIBUTE; + } + return a->QueryBoolValue( value ); + } + /// See QueryIntAttribute() + XMLError QueryDoubleAttribute( const char* name, double* value ) const { + const XMLAttribute* a = FindAttribute( name ); + if ( !a ) { + return XML_NO_ATTRIBUTE; + } + return a->QueryDoubleValue( value ); + } + /// See QueryIntAttribute() + XMLError QueryFloatAttribute( const char* name, float* value ) const { + const XMLAttribute* a = FindAttribute( name ); + if ( !a ) { + return XML_NO_ATTRIBUTE; + } + return a->QueryFloatValue( value ); + } + + /// See QueryIntAttribute() + XMLError QueryStringAttribute(const char* name, const char** value) const { + const XMLAttribute* a = FindAttribute(name); + if (!a) { + return XML_NO_ATTRIBUTE; + } + *value = a->Value(); + return XML_SUCCESS; + } + + + + /** Given an attribute name, QueryAttribute() returns + XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion + can't be performed, or XML_NO_ATTRIBUTE if the attribute + doesn't exist. It is overloaded for the primitive types, + and is a generally more convenient replacement of + QueryIntAttribute() and related functions. + + If successful, the result of the conversion + will be written to 'value'. If not successful, nothing will + be written to 'value'. This allows you to provide default + value: + + @verbatim + int value = 10; + QueryAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 + @endverbatim + */ + XMLError QueryAttribute( const char* name, int* value ) const { + return QueryIntAttribute( name, value ); + } + + XMLError QueryAttribute( const char* name, unsigned int* value ) const { + return QueryUnsignedAttribute( name, value ); + } + + XMLError QueryAttribute(const char* name, int64_t* value) const { + return QueryInt64Attribute(name, value); + } + + XMLError QueryAttribute(const char* name, uint64_t* value) const { + return QueryUnsigned64Attribute(name, value); + } + + XMLError QueryAttribute( const char* name, bool* value ) const { + return QueryBoolAttribute( name, value ); + } + + XMLError QueryAttribute( const char* name, double* value ) const { + return QueryDoubleAttribute( name, value ); + } + + XMLError QueryAttribute( const char* name, float* value ) const { + return QueryFloatAttribute( name, value ); + } + + XMLError QueryAttribute(const char* name, const char** value) const { + return QueryStringAttribute(name, value); + } + + /// Sets the named attribute to value. + void SetAttribute( const char* name, const char* value ) { + XMLAttribute* a = FindOrCreateAttribute( name ); + a->SetAttribute( value ); + } + /// Sets the named attribute to value. + void SetAttribute( const char* name, int value ) { + XMLAttribute* a = FindOrCreateAttribute( name ); + a->SetAttribute( value ); + } + /// Sets the named attribute to value. + void SetAttribute( const char* name, unsigned value ) { + XMLAttribute* a = FindOrCreateAttribute( name ); + a->SetAttribute( value ); + } + + /// Sets the named attribute to value. + void SetAttribute(const char* name, int64_t value) { + XMLAttribute* a = FindOrCreateAttribute(name); + a->SetAttribute(value); + } + + /// Sets the named attribute to value. + void SetAttribute(const char* name, uint64_t value) { + XMLAttribute* a = FindOrCreateAttribute(name); + a->SetAttribute(value); + } + + /// Sets the named attribute to value. + void SetAttribute( const char* name, bool value ) { + XMLAttribute* a = FindOrCreateAttribute( name ); + a->SetAttribute( value ); + } + /// Sets the named attribute to value. + void SetAttribute( const char* name, double value ) { + XMLAttribute* a = FindOrCreateAttribute( name ); + a->SetAttribute( value ); + } + /// Sets the named attribute to value. + void SetAttribute( const char* name, float value ) { + XMLAttribute* a = FindOrCreateAttribute( name ); + a->SetAttribute( value ); + } + + /** + Delete an attribute. + */ + void DeleteAttribute( const char* name ); + + /// Return the first attribute in the list. + const XMLAttribute* FirstAttribute() const { + return _rootAttribute; + } + /// Query a specific attribute in the list. + const XMLAttribute* FindAttribute( const char* name ) const; + + /** Convenience function for easy access to the text inside an element. Although easy + and concise, GetText() is limited compared to getting the XMLText child + and accessing it directly. + + If the first child of 'this' is a XMLText, the GetText() + returns the character string of the Text node, else null is returned. + + This is a convenient method for getting the text of simple contained text: + @verbatim + This is text + const char* str = fooElement->GetText(); + @endverbatim + + 'str' will be a pointer to "This is text". + + Note that this function can be misleading. If the element foo was created from + this XML: + @verbatim + This is text + @endverbatim + + then the value of str would be null. The first child node isn't a text node, it is + another element. From this XML: + @verbatim + This is text + @endverbatim + GetText() will return "This is ". + */ + const char* GetText() const; + + /** Convenience function for easy access to the text inside an element. Although easy + and concise, SetText() is limited compared to creating an XMLText child + and mutating it directly. + + If the first child of 'this' is a XMLText, SetText() sets its value to + the given string, otherwise it will create a first child that is an XMLText. + + This is a convenient method for setting the text of simple contained text: + @verbatim + This is text + fooElement->SetText( "Hullaballoo!" ); + Hullaballoo! + @endverbatim + + Note that this function can be misleading. If the element foo was created from + this XML: + @verbatim + This is text + @endverbatim + + then it will not change "This is text", but rather prefix it with a text element: + @verbatim + Hullaballoo!This is text + @endverbatim + + For this XML: + @verbatim + + @endverbatim + SetText() will generate + @verbatim + Hullaballoo! + @endverbatim + */ + void SetText( const char* inText ); + /// Convenience method for setting text inside an element. See SetText() for important limitations. + void SetText( int value ); + /// Convenience method for setting text inside an element. See SetText() for important limitations. + void SetText( unsigned value ); + /// Convenience method for setting text inside an element. See SetText() for important limitations. + void SetText(int64_t value); + /// Convenience method for setting text inside an element. See SetText() for important limitations. + void SetText(uint64_t value); + /// Convenience method for setting text inside an element. See SetText() for important limitations. + void SetText( bool value ); + /// Convenience method for setting text inside an element. See SetText() for important limitations. + void SetText( double value ); + /// Convenience method for setting text inside an element. See SetText() for important limitations. + void SetText( float value ); + + /** + Convenience method to query the value of a child text node. This is probably best + shown by example. Given you have a document is this form: + @verbatim + + 1 + 1.4 + + @endverbatim + + The QueryIntText() and similar functions provide a safe and easier way to get to the + "value" of x and y. + + @verbatim + int x = 0; + float y = 0; // types of x and y are contrived for example + const XMLElement* xElement = pointElement->FirstChildElement( "x" ); + const XMLElement* yElement = pointElement->FirstChildElement( "y" ); + xElement->QueryIntText( &x ); + yElement->QueryFloatText( &y ); + @endverbatim + + @returns XML_SUCCESS (0) on success, XML_CAN_NOT_CONVERT_TEXT if the text cannot be converted + to the requested type, and XML_NO_TEXT_NODE if there is no child text to query. + + */ + XMLError QueryIntText( int* ival ) const; + /// See QueryIntText() + XMLError QueryUnsignedText( unsigned* uval ) const; + /// See QueryIntText() + XMLError QueryInt64Text(int64_t* uval) const; + /// See QueryIntText() + XMLError QueryUnsigned64Text(uint64_t* uval) const; + /// See QueryIntText() + XMLError QueryBoolText( bool* bval ) const; + /// See QueryIntText() + XMLError QueryDoubleText( double* dval ) const; + /// See QueryIntText() + XMLError QueryFloatText( float* fval ) const; + + int IntText(int defaultValue = 0) const; + + /// See QueryIntText() + unsigned UnsignedText(unsigned defaultValue = 0) const; + /// See QueryIntText() + int64_t Int64Text(int64_t defaultValue = 0) const; + /// See QueryIntText() + uint64_t Unsigned64Text(uint64_t defaultValue = 0) const; + /// See QueryIntText() + bool BoolText(bool defaultValue = false) const; + /// See QueryIntText() + double DoubleText(double defaultValue = 0) const; + /// See QueryIntText() + float FloatText(float defaultValue = 0) const; + + /** + Convenience method to create a new XMLElement and add it as last (right) + child of this node. Returns the created and inserted element. + */ + XMLElement* InsertNewChildElement(const char* name); + /// See InsertNewChildElement() + XMLComment* InsertNewComment(const char* comment); + /// See InsertNewChildElement() + XMLText* InsertNewText(const char* text); + /// See InsertNewChildElement() + XMLDeclaration* InsertNewDeclaration(const char* text); + /// See InsertNewChildElement() + XMLUnknown* InsertNewUnknown(const char* text); + + + // internal: + enum ElementClosingType { + OPEN, // + CLOSED, // + CLOSING // + }; + ElementClosingType ClosingType() const { + return _closingType; + } + virtual XMLNode* ShallowClone( XMLDocument* document ) const override; + virtual bool ShallowEqual( const XMLNode* compare ) const override; + +protected: + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override; + +private: + XMLElement( XMLDocument* doc ); + virtual ~XMLElement(); + XMLElement( const XMLElement& ); // not supported + void operator=( const XMLElement& ); // not supported + + XMLAttribute* FindOrCreateAttribute( const char* name ); + char* ParseAttributes( char* p, int* curLineNumPtr ); + static void DeleteAttribute( XMLAttribute* attribute ); + XMLAttribute* CreateAttribute(); + + enum { BUF_SIZE = 200 }; + ElementClosingType _closingType; + // The attribute list is ordered; there is no 'lastAttribute' + // because the list needs to be scanned for dupes before adding + // a new attribute. + XMLAttribute* _rootAttribute; +}; + + +enum Whitespace { + PRESERVE_WHITESPACE, + COLLAPSE_WHITESPACE, + PEDANTIC_WHITESPACE +}; + + +/** A Document binds together all the functionality. + It can be saved, loaded, and printed to the screen. + All Nodes are connected and allocated to a Document. + If the Document is deleted, all its Nodes are also deleted. +*/ +class TINYXML2_LIB XMLDocument : public XMLNode +{ + friend class XMLElement; + // Gives access to SetError and Push/PopDepth, but over-access for everything else. + // Wishing C++ had "internal" scope. + friend class XMLNode; + friend class XMLText; + friend class XMLComment; + friend class XMLDeclaration; + friend class XMLUnknown; +public: + /// constructor + XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE ); + ~XMLDocument(); + + virtual XMLDocument* ToDocument() override { + TIXMLASSERT( this == _document ); + return this; + } + virtual const XMLDocument* ToDocument() const override { + TIXMLASSERT( this == _document ); + return this; + } + + /** + Parse an XML file from a character string. + Returns XML_SUCCESS (0) on success, or + an errorID. + + You may optionally pass in the 'nBytes', which is + the number of bytes which will be parsed. If not + specified, TinyXML-2 will assume 'xml' points to a + null terminated string. + */ + XMLError Parse( const char* xml, size_t nBytes=static_cast(-1) ); + + /** + Load an XML file from disk. + Returns XML_SUCCESS (0) on success, or + an errorID. + */ + XMLError LoadFile( const char* filename ); + + /** + Load an XML file from disk. You are responsible + for providing and closing the FILE*. + + NOTE: The file should be opened as binary ("rb") + not text in order for TinyXML-2 to correctly + do newline normalization. + + Returns XML_SUCCESS (0) on success, or + an errorID. + */ + XMLError LoadFile( FILE* ); + + /** + Save the XML file to disk. + Returns XML_SUCCESS (0) on success, or + an errorID. + */ + XMLError SaveFile( const char* filename, bool compact = false ); + + /** + Save the XML file to disk. You are responsible + for providing and closing the FILE*. + + Returns XML_SUCCESS (0) on success, or + an errorID. + */ + XMLError SaveFile( FILE* fp, bool compact = false ); + + bool ProcessEntities() const { + return _processEntities; + } + Whitespace WhitespaceMode() const { + return _whitespaceMode; + } + + /** + Returns true if this document has a leading Byte Order Mark of UTF8. + */ + bool HasBOM() const { + return _writeBOM; + } + /** Sets whether to write the BOM when writing the file. + */ + void SetBOM( bool useBOM ) { + _writeBOM = useBOM; + } + + /** Return the root element of DOM. Equivalent to FirstChildElement(). + To get the first node, use FirstChild(). + */ + XMLElement* RootElement() { + return FirstChildElement(); + } + const XMLElement* RootElement() const { + return FirstChildElement(); + } + + /** Print the Document. If the Printer is not provided, it will + print to stdout. If you provide Printer, this can print to a file: + @verbatim + XMLPrinter printer( fp ); + doc.Print( &printer ); + @endverbatim + + Or you can use a printer to print to memory: + @verbatim + XMLPrinter printer; + doc.Print( &printer ); + // printer.CStr() has a const char* to the XML + @endverbatim + */ + void Print( XMLPrinter* streamer=0 ) const; + virtual bool Accept( XMLVisitor* visitor ) const override; + + /** + Create a new Element associated with + this Document. The memory for the Element + is managed by the Document. + */ + XMLElement* NewElement( const char* name ); + /** + Create a new Comment associated with + this Document. The memory for the Comment + is managed by the Document. + */ + XMLComment* NewComment( const char* comment ); + /** + Create a new Text associated with + this Document. The memory for the Text + is managed by the Document. + */ + XMLText* NewText( const char* text ); + /** + Create a new Declaration associated with + this Document. The memory for the object + is managed by the Document. + + If the 'text' param is null, the standard + declaration is used.: + @verbatim + + @endverbatim + */ + XMLDeclaration* NewDeclaration( const char* text=0 ); + /** + Create a new Unknown associated with + this Document. The memory for the object + is managed by the Document. + */ + XMLUnknown* NewUnknown( const char* text ); + + /** + Delete a node associated with this document. + It will be unlinked from the DOM. + */ + void DeleteNode( XMLNode* node ); + + /// Clears the error flags. + void ClearError(); + + /// Return true if there was an error parsing the document. + bool Error() const { + return _errorID != XML_SUCCESS; + } + /// Return the errorID. + XMLError ErrorID() const { + return _errorID; + } + const char* ErrorName() const; + static const char* ErrorIDToName(XMLError errorID); + + /** Returns a "long form" error description. A hopefully helpful + diagnostic with location, line number, and/or additional info. + */ + const char* ErrorStr() const; + + /// A (trivial) utility function that prints the ErrorStr() to stdout. + void PrintError() const; + + /// Return the line where the error occurred, or zero if unknown. + int ErrorLineNum() const + { + return _errorLineNum; + } + + /// Clear the document, resetting it to the initial state. + void Clear(); + + /** + Copies this document to a target document. + The target will be completely cleared before the copy. + If you want to copy a sub-tree, see XMLNode::DeepClone(). + + NOTE: that the 'target' must be non-null. + */ + void DeepCopy(XMLDocument* target) const; + + // internal + char* Identify( char* p, XMLNode** node, bool first ); + + // internal + void MarkInUse(const XMLNode* const); + + virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const override{ + return 0; + } + virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const override{ + return false; + } + +private: + XMLDocument( const XMLDocument& ); // not supported + void operator=( const XMLDocument& ); // not supported + + bool _writeBOM; + bool _processEntities; + XMLError _errorID; + Whitespace _whitespaceMode; + mutable StrPair _errorStr; + int _errorLineNum; + char* _charBuffer; + int _parseCurLineNum; + int _parsingDepth; + // Memory tracking does add some overhead. + // However, the code assumes that you don't + // have a bunch of unlinked nodes around. + // Therefore it takes less memory to track + // in the document vs. a linked list in the XMLNode, + // and the performance is the same. + DynArray _unlinked; + + MemPoolT< sizeof(XMLElement) > _elementPool; + MemPoolT< sizeof(XMLAttribute) > _attributePool; + MemPoolT< sizeof(XMLText) > _textPool; + MemPoolT< sizeof(XMLComment) > _commentPool; + + static const char* _errorNames[XML_ERROR_COUNT]; + + void Parse(); + + void SetError( XMLError error, int lineNum, const char* format, ... ); + + // Something of an obvious security hole, once it was discovered. + // Either an ill-formed XML or an excessively deep one can overflow + // the stack. Track stack depth, and error out if needed. + class DepthTracker { + public: + explicit DepthTracker(XMLDocument * document) { + this->_document = document; + document->PushDepth(); + } + ~DepthTracker() { + _document->PopDepth(); + } + private: + XMLDocument * _document; + }; + void PushDepth(); + void PopDepth(); + + template + NodeType* CreateUnlinkedNode( MemPoolT& pool ); +}; + +template +inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT& pool ) +{ + TIXMLASSERT( sizeof( NodeType ) == PoolElementSize ); + TIXMLASSERT( sizeof( NodeType ) == pool.ItemSize() ); + NodeType* returnNode = new (pool.Alloc()) NodeType( this ); + TIXMLASSERT( returnNode ); + returnNode->_memPool = &pool; + + _unlinked.Push(returnNode); + return returnNode; +} + +/** + A XMLHandle is a class that wraps a node pointer with null checks; this is + an incredibly useful thing. Note that XMLHandle is not part of the TinyXML-2 + DOM structure. It is a separate utility class. + + Take an example: + @verbatim + + + + + + + @endverbatim + + Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very + easy to write a *lot* of code that looks like: + + @verbatim + XMLElement* root = document.FirstChildElement( "Document" ); + if ( root ) + { + XMLElement* element = root->FirstChildElement( "Element" ); + if ( element ) + { + XMLElement* child = element->FirstChildElement( "Child" ); + if ( child ) + { + XMLElement* child2 = child->NextSiblingElement( "Child" ); + if ( child2 ) + { + // Finally do something useful. + @endverbatim + + And that doesn't even cover "else" cases. XMLHandle addresses the verbosity + of such code. A XMLHandle checks for null pointers so it is perfectly safe + and correct to use: + + @verbatim + XMLHandle docHandle( &document ); + XMLElement* child2 = docHandle.FirstChildElement( "Document" ).FirstChildElement( "Element" ).FirstChildElement().NextSiblingElement(); + if ( child2 ) + { + // do something useful + @endverbatim + + Which is MUCH more concise and useful. + + It is also safe to copy handles - internally they are nothing more than node pointers. + @verbatim + XMLHandle handleCopy = handle; + @endverbatim + + See also XMLConstHandle, which is the same as XMLHandle, but operates on const objects. +*/ +class TINYXML2_LIB XMLHandle +{ +public: + /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. + explicit XMLHandle( XMLNode* node ) : _node( node ) { + } + /// Create a handle from a node. + explicit XMLHandle( XMLNode& node ) : _node( &node ) { + } + /// Copy constructor + XMLHandle( const XMLHandle& ref ) : _node( ref._node ) { + } + /// Assignment + XMLHandle& operator=( const XMLHandle& ref ) { + _node = ref._node; + return *this; + } + + /// Get the first child of this handle. + XMLHandle FirstChild() { + return XMLHandle( _node ? _node->FirstChild() : 0 ); + } + /// Get the first child element of this handle. + XMLHandle FirstChildElement( const char* name = 0 ) { + return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 ); + } + /// Get the last child of this handle. + XMLHandle LastChild() { + return XMLHandle( _node ? _node->LastChild() : 0 ); + } + /// Get the last child element of this handle. + XMLHandle LastChildElement( const char* name = 0 ) { + return XMLHandle( _node ? _node->LastChildElement( name ) : 0 ); + } + /// Get the previous sibling of this handle. + XMLHandle PreviousSibling() { + return XMLHandle( _node ? _node->PreviousSibling() : 0 ); + } + /// Get the previous sibling element of this handle. + XMLHandle PreviousSiblingElement( const char* name = 0 ) { + return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 ); + } + /// Get the next sibling of this handle. + XMLHandle NextSibling() { + return XMLHandle( _node ? _node->NextSibling() : 0 ); + } + /// Get the next sibling element of this handle. + XMLHandle NextSiblingElement( const char* name = 0 ) { + return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 ); + } + + /// Safe cast to XMLNode. This can return null. + XMLNode* ToNode() { + return _node; + } + /// Safe cast to XMLElement. This can return null. + XMLElement* ToElement() { + return ( _node ? _node->ToElement() : 0 ); + } + /// Safe cast to XMLText. This can return null. + XMLText* ToText() { + return ( _node ? _node->ToText() : 0 ); + } + /// Safe cast to XMLUnknown. This can return null. + XMLUnknown* ToUnknown() { + return ( _node ? _node->ToUnknown() : 0 ); + } + /// Safe cast to XMLDeclaration. This can return null. + XMLDeclaration* ToDeclaration() { + return ( _node ? _node->ToDeclaration() : 0 ); + } + +private: + XMLNode* _node; +}; + + +/** + A variant of the XMLHandle class for working with const XMLNodes and Documents. It is the + same in all regards, except for the 'const' qualifiers. See XMLHandle for API. +*/ +class TINYXML2_LIB XMLConstHandle +{ +public: + explicit XMLConstHandle( const XMLNode* node ) : _node( node ) { + } + explicit XMLConstHandle( const XMLNode& node ) : _node( &node ) { + } + XMLConstHandle( const XMLConstHandle& ref ) : _node( ref._node ) { + } + + XMLConstHandle& operator=( const XMLConstHandle& ref ) { + _node = ref._node; + return *this; + } + + const XMLConstHandle FirstChild() const { + return XMLConstHandle( _node ? _node->FirstChild() : 0 ); + } + const XMLConstHandle FirstChildElement( const char* name = 0 ) const { + return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 ); + } + const XMLConstHandle LastChild() const { + return XMLConstHandle( _node ? _node->LastChild() : 0 ); + } + const XMLConstHandle LastChildElement( const char* name = 0 ) const { + return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 ); + } + const XMLConstHandle PreviousSibling() const { + return XMLConstHandle( _node ? _node->PreviousSibling() : 0 ); + } + const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const { + return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 ); + } + const XMLConstHandle NextSibling() const { + return XMLConstHandle( _node ? _node->NextSibling() : 0 ); + } + const XMLConstHandle NextSiblingElement( const char* name = 0 ) const { + return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 ); + } + + + const XMLNode* ToNode() const { + return _node; + } + const XMLElement* ToElement() const { + return ( _node ? _node->ToElement() : 0 ); + } + const XMLText* ToText() const { + return ( _node ? _node->ToText() : 0 ); + } + const XMLUnknown* ToUnknown() const { + return ( _node ? _node->ToUnknown() : 0 ); + } + const XMLDeclaration* ToDeclaration() const { + return ( _node ? _node->ToDeclaration() : 0 ); + } + +private: + const XMLNode* _node; +}; + + +/** + Printing functionality. The XMLPrinter gives you more + options than the XMLDocument::Print() method. + + It can: + -# Print to memory. + -# Print to a file you provide. + -# Print XML without a XMLDocument. + + Print to Memory + + @verbatim + XMLPrinter printer; + doc.Print( &printer ); + SomeFunction( printer.CStr() ); + @endverbatim + + Print to a File + + You provide the file pointer. + @verbatim + XMLPrinter printer( fp ); + doc.Print( &printer ); + @endverbatim + + Print without a XMLDocument + + When loading, an XML parser is very useful. However, sometimes + when saving, it just gets in the way. The code is often set up + for streaming, and constructing the DOM is just overhead. + + The Printer supports the streaming case. The following code + prints out a trivially simple XML file without ever creating + an XML document. + + @verbatim + XMLPrinter printer( fp ); + printer.OpenElement( "foo" ); + printer.PushAttribute( "foo", "bar" ); + printer.CloseElement(); + @endverbatim +*/ +class TINYXML2_LIB XMLPrinter : public XMLVisitor +{ +public: + /** Construct the printer. If the FILE* is specified, + this will print to the FILE. Else it will print + to memory, and the result is available in CStr(). + If 'compact' is set to true, then output is created + with only required whitespace and newlines. + */ + XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 ); + virtual ~XMLPrinter() {} + + /** If streaming, write the BOM and declaration. */ + void PushHeader( bool writeBOM, bool writeDeclaration ); + /** If streaming, start writing an element. + The element must be closed with CloseElement() + */ + void OpenElement( const char* name, bool compactMode=false ); + /// If streaming, add an attribute to an open element. + void PushAttribute( const char* name, const char* value ); + void PushAttribute( const char* name, int value ); + void PushAttribute( const char* name, unsigned value ); + void PushAttribute( const char* name, int64_t value ); + void PushAttribute( const char* name, uint64_t value ); + void PushAttribute( const char* name, bool value ); + void PushAttribute( const char* name, double value ); + /// If streaming, close the Element. + virtual void CloseElement( bool compactMode=false ); + + /// Add a text node. + void PushText( const char* text, bool cdata=false ); + /// Add a text node from an integer. + void PushText( int value ); + /// Add a text node from an unsigned. + void PushText( unsigned value ); + /// Add a text node from a signed 64bit integer. + void PushText( int64_t value ); + /// Add a text node from an unsigned 64bit integer. + void PushText( uint64_t value ); + /// Add a text node from a bool. + void PushText( bool value ); + /// Add a text node from a float. + void PushText( float value ); + /// Add a text node from a double. + void PushText( double value ); + + /// Add a comment + void PushComment( const char* comment ); + + void PushDeclaration( const char* value ); + void PushUnknown( const char* value ); + + virtual bool VisitEnter( const XMLDocument& /*doc*/ ) override; + virtual bool VisitExit( const XMLDocument& /*doc*/ ) override { + return true; + } + + virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute ) override; + virtual bool VisitExit( const XMLElement& element ) override; + + virtual bool Visit( const XMLText& text ) override; + virtual bool Visit( const XMLComment& comment ) override; + virtual bool Visit( const XMLDeclaration& declaration ) override; + virtual bool Visit( const XMLUnknown& unknown ) override; + + /** + If in print to memory mode, return a pointer to + the XML file in memory. + */ + const char* CStr() const { + return _buffer.Mem(); + } + /** + If in print to memory mode, return the size + of the XML file in memory. (Note the size returned + includes the terminating null.) + */ + size_t CStrSize() const { + return _buffer.Size(); + } + /** + If in print to memory mode, reset the buffer to the + beginning. + */ + void ClearBuffer( bool resetToFirstElement = true ) { + _buffer.Clear(); + _buffer.Push(0); + _firstElement = resetToFirstElement; + } + +protected: + virtual bool CompactMode( const XMLElement& ) { return _compactMode; } + + /** Prints out the space before an element. You may override to change + the space and tabs used. A PrintSpace() override should call Print(). + */ + virtual void PrintSpace( int depth ); + virtual void Print( const char* format, ... ); + virtual void Write( const char* data, size_t size ); + virtual void Putc( char ch ); + + inline void Write(const char* data) { Write(data, strlen(data)); } + + void SealElementIfJustOpened(); + bool _elementJustOpened; + DynArray< const char*, 10 > _stack; + +private: + /** + Prepares to write a new node. This includes sealing an element that was + just opened, and writing any whitespace necessary if not in compact mode. + */ + void PrepareForNewNode( bool compactMode ); + void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities. + + bool _firstElement; + FILE* _fp; + int _depth; + int _textDepth; + bool _processEntities; + bool _compactMode; + + enum { + ENTITY_RANGE = 64, + BUF_SIZE = 200 + }; + bool _entityFlag[ENTITY_RANGE]; + bool _restrictedEntityFlag[ENTITY_RANGE]; + + DynArray< char, 20 > _buffer; + + // Prohibit cloning, intentionally not implemented + XMLPrinter( const XMLPrinter& ); + XMLPrinter& operator=( const XMLPrinter& ); +}; + + +} // namespace tinyxml2 + +#if defined(_MSC_VER) +# pragma warning(pop) +#endif + +#endif // TINYXML2_INCLUDED From 865aa1d4f0884827b96c63384eff323c956688c7 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 31 Mar 2025 04:38:17 +0500 Subject: [PATCH 116/167] KASM-6984 Refactor SelfBench --- common/rfb/SelfBench.cxx | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/common/rfb/SelfBench.cxx b/common/rfb/SelfBench.cxx index 550d6dd..ca8e3fb 100644 --- a/common/rfb/SelfBench.cxx +++ b/common/rfb/SelfBench.cxx @@ -41,12 +41,6 @@ static constexpr uint32_t RUNS = 64; static constexpr uint32_t WIDTH = 1600; static constexpr uint32_t HEIGHT = 1200; -template -constexpr bool has_no_args = std::is_invocable_v; - -template -constexpr bool has_one_arg = std::is_invocable_v; - void SelfBench() { tinyxml2::XMLDocument doc; @@ -98,11 +92,11 @@ void SelfBench() { } auto value = elapsedMs(now); - vlog.info("%s took %lu ms (%u runs)", name, value, RUNS); + vlog.info("%s took %lu ms (%u runs)", name, value, runs); auto *test_case = doc.NewElement("testcase"); test_case->SetAttribute("name", name); test_case->SetAttribute("time", value); - test_case->SetAttribute("runs", RUNS); + test_case->SetAttribute("runs", runs); test_suit->InsertEndChild(test_case); }; @@ -186,8 +180,7 @@ void SelfBench() { comparer->compare(false, cursorReg); }); - vlog.info("Before"); doc.SaveFile("SelfBench.xml"); - vlog.info("after"); + exit(0); } From 44ee8ee58a086cac3e247b1dd7beaa18f1ef6f8a Mon Sep 17 00:00:00 2001 From: El Date: Mon, 31 Mar 2025 04:38:55 +0500 Subject: [PATCH 117/167] KASM-6984 Refactor TinyXML2 integration and update build settings --- CMakeLists.txt | 2 +- common/rfb/CMakeLists.txt | 230 ++++++++++++++-------------- third_party/CMakeLists.txt | 1 + third_party/tinyxml2/CMakeLists.txt | 5 + 4 files changed, 125 insertions(+), 113 deletions(-) create mode 100644 third_party/CMakeLists.txt create mode 100644 third_party/tinyxml2/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 537063e..7a509b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,6 @@ set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -UNDEBUG") # Make sure we get a sane C version set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") -set(CMAKE_CXX_STANDARD 20) # Enable OpenMP set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp") @@ -227,6 +226,7 @@ include_directories(${CMAKE_BINARY_DIR}) include(cmake/StaticBuild.cmake) +add_subdirectory(third_party) add_subdirectory(common) if(WIN32) diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt index 70217fe..56f4488 100644 --- a/common/rfb/CMakeLists.txt +++ b/common/rfb/CMakeLists.txt @@ -1,84 +1,82 @@ -include_directories(${CMAKE_SOURCE_DIR}/common ${JPEG_INCLUDE_DIR} ${PNG_INCLUDE_DIR} - ${CMAKE_SOURCE_DIR}/unix/kasmvncpasswd) - set(RFB_SOURCES - Blacklist.cxx - Congestion.cxx - CConnection.cxx - CMsgHandler.cxx - CMsgReader.cxx - CMsgWriter.cxx - CSecurityPlain.cxx - CSecurityStack.cxx - CSecurityVeNCrypt.cxx - CSecurityVncAuth.cxx - ComparingUpdateTracker.cxx - Configuration.cxx - ConnParams.cxx - CopyRectDecoder.cxx - Cursor.cxx - DecodeManager.cxx - Decoder.cxx - d3des.c - EncCache.cxx - EncodeManager.cxx - Encoder.cxx - HextileDecoder.cxx - HextileEncoder.cxx - JpegCompressor.cxx - JpegDecompressor.cxx - KeyRemapper.cxx - LogWriter.cxx - Logger.cxx - Logger_file.cxx - Logger_stdio.cxx - Password.cxx - PixelBuffer.cxx - PixelFormat.cxx - RREEncoder.cxx - RREDecoder.cxx - RawDecoder.cxx - RawEncoder.cxx - Region.cxx - SConnection.cxx - SMsgHandler.cxx - SMsgReader.cxx - SMsgWriter.cxx - ServerCore.cxx - Security.cxx - SecurityServer.cxx - SecurityClient.cxx - SelfBench.cxx - SSecurityPlain.cxx - SSecurityStack.cxx - SSecurityVncAuth.cxx - SSecurityVeNCrypt.cxx - ScaleFilters.cxx - Timer.cxx - TightDecoder.cxx - TightEncoder.cxx - TightJPEGEncoder.cxx - TightWEBPEncoder.cxx - TightQOIEncoder.cxx - UpdateTracker.cxx - VNCSConnectionST.cxx - VNCServerST.cxx - ZRLEEncoder.cxx - ZRLEDecoder.cxx - Watermark.cxx - cpuid.cxx - encodings.cxx - util.cxx - xxhash.c) + Blacklist.cxx + Congestion.cxx + CConnection.cxx + CMsgHandler.cxx + CMsgReader.cxx + CMsgWriter.cxx + CSecurityPlain.cxx + CSecurityStack.cxx + CSecurityVeNCrypt.cxx + CSecurityVncAuth.cxx + ComparingUpdateTracker.cxx + Configuration.cxx + ConnParams.cxx + CopyRectDecoder.cxx + Cursor.cxx + DecodeManager.cxx + Decoder.cxx + d3des.c + EncCache.cxx + EncodeManager.cxx + Encoder.cxx + HextileDecoder.cxx + HextileEncoder.cxx + JpegCompressor.cxx + JpegDecompressor.cxx + KeyRemapper.cxx + LogWriter.cxx + Logger.cxx + Logger_file.cxx + Logger_stdio.cxx + Password.cxx + PixelBuffer.cxx + PixelFormat.cxx + RREEncoder.cxx + RREDecoder.cxx + RawDecoder.cxx + RawEncoder.cxx + Region.cxx + SConnection.cxx + SMsgHandler.cxx + SMsgReader.cxx + SMsgWriter.cxx + ServerCore.cxx + Security.cxx + SecurityServer.cxx + SecurityClient.cxx + SelfBench.cxx + SSecurityPlain.cxx + SSecurityStack.cxx + SSecurityVncAuth.cxx + SSecurityVeNCrypt.cxx + ScaleFilters.cxx + Timer.cxx + TightDecoder.cxx + TightEncoder.cxx + TightJPEGEncoder.cxx + TightWEBPEncoder.cxx + TightQOIEncoder.cxx + UpdateTracker.cxx + VNCSConnectionST.cxx + VNCServerST.cxx + ZRLEEncoder.cxx + ZRLEDecoder.cxx + Watermark.cxx + cpuid.cxx + encodings.cxx + util.cxx + xxhash.c +) -if(UNIX) - set(RFB_SOURCES ${RFB_SOURCES} Logger_syslog.cxx) -endif() +if (UNIX) + set(RFB_SOURCES ${RFB_SOURCES} Logger_syslog.cxx) +endif () -if(WIN32) - include_directories(${CMAKE_SOURCE_DIR}/win) - set(RFB_SOURCES ${RFB_SOURCES} WinPasswdValidator.cxx) -endif(WIN32) +if (WIN32) + include_directories(${CMAKE_SOURCE_DIR}/win) + set(RFB_SOURCES ${RFB_SOURCES} WinPasswdValidator.cxx) +endif (WIN32) set(RFB_LIBRARIES ${JPEG_LIBRARIES} ${PNG_LIBRARIES} os rdr Xregion) @@ -88,49 +86,57 @@ if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_ set(RFB_LIBRARIES ${RFB_LIBRARIES} tbb) endif () -if(HAVE_PAM) - set(RFB_SOURCES ${RFB_SOURCES} UnixPasswordValidator.cxx - UnixPasswordValidator.h pam.c pam.h) - set(RFB_LIBRARIES ${RFB_LIBRARIES} ${PAM_LIBS}) -endif() +if (HAVE_PAM) + set(RFB_SOURCES ${RFB_SOURCES} UnixPasswordValidator.cxx + UnixPasswordValidator.h pam.c pam.h) + set(RFB_LIBRARIES ${RFB_LIBRARIES} ${PAM_LIBS}) +endif () -if(GNUTLS_FOUND) - set(RFB_SOURCES - ${RFB_SOURCES} - CSecurityTLS.cxx - SSecurityTLS.cxx - ) - set(RFB_LIBRARIES - ${RFB_LIBRARIES} - ${GNUTLS_LIBRARIES} - ) -endif() +if (GNUTLS_FOUND) + set(RFB_SOURCES + ${RFB_SOURCES} + CSecurityTLS.cxx + SSecurityTLS.cxx + ) + set(RFB_LIBRARIES + ${RFB_LIBRARIES} + ${GNUTLS_LIBRARIES} + ) +endif () # SSE2 set(SSE2_SOURCES - scale_sse2.cxx) + scale_sse2.cxx) set(SCALE_DUMMY_SOURCES - scale_dummy.cxx) + scale_dummy.cxx) -if(COMPILER_SUPPORTS_SSE2) - set_source_files_properties(${SSE2_SOURCES} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS} -msse2) - set(RFB_SOURCES - ${RFB_SOURCES} - ${SSE2_SOURCES} - ) -else() - set(RFB_SOURCES - ${RFB_SOURCES} - ${SCALE_DUMMY_SOURCES} - ) -endif() +if (COMPILER_SUPPORTS_SSE2) + set_source_files_properties(${SSE2_SOURCES} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS} -msse2) + set(RFB_SOURCES + ${RFB_SOURCES} + ${SSE2_SOURCES} + ) +else () + set(RFB_SOURCES + ${RFB_SOURCES} + ${SCALE_DUMMY_SOURCES} + ) +endif () add_library(rfb STATIC ${RFB_SOURCES}) -target_link_libraries(rfb ${RFB_LIBRARIES}) +target_include_directories(rfb PRIVATE + ${CMAKE_SOURCE_DIR}/common + ${JPEG_INCLUDE_DIR} + ${PNG_INCLUDE_DIR} + ${CMAKE_SOURCE_DIR}/unix/kasmvncpasswd + ${CMAKE_SOURCE_DIR}/third_party/tinyxml2 +) -if(UNIX) - libtool_create_control_file(rfb) -endif() +target_link_libraries(rfb PRIVATE ${RFB_LIBRARIES} tinyxml2_objs) + +if (UNIX) + libtool_create_control_file(rfb) +endif () diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt new file mode 100644 index 0000000..8572f8d --- /dev/null +++ b/third_party/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(tinyxml2) \ No newline at end of file diff --git a/third_party/tinyxml2/CMakeLists.txt b/third_party/tinyxml2/CMakeLists.txt new file mode 100644 index 0000000..db809df --- /dev/null +++ b/third_party/tinyxml2/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(tinyxml2_objs OBJECT tinyxml2.cpp) +if (NOT WIN32) + set_target_properties(tinyxml2_objs PROPERTIES POSITION_INDEPENDENT_CODE ON) +endif () +target_include_directories(tinyxml2_objs PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file From 75b1712f31e8cb6890098d98576e3cdb885c3fc8 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 31 Mar 2025 07:46:07 +0500 Subject: [PATCH 118/167] KASM-6984 Refactor GitLab CI to utilize job extensions and reduce redundancy --- .gitlab-ci.yml | 869 +++++++++------------------- spec/helper/spec_helper.py | 13 + spec/vncserver_benchmarking_spec.py | 12 + 3 files changed, 287 insertions(+), 607 deletions(-) create mode 100644 spec/vncserver_benchmarking_spec.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e234c79..e104a69 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -66,18 +66,14 @@ build_www: paths: - output/ -build_ubuntu_focal: +.base_build: stage: build allow_failure: true - tags: - - oci-fixed-amd before_script: - *prepare_build - *prepare_www after_script: - *prepare_artfacts - script: - - bash builder/build-package ubuntu focal; only: variables: - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME @@ -85,444 +81,197 @@ build_ubuntu_focal: paths: - output/ +build_ubuntu_focal: + extends: + - .base_build + tags: + - oci-fixed-amd + script: + - bash builder/build-package ubuntu focal; + build_ubuntu_focal_arm: - stage: build - allow_failure: true + extends: + - .base_build tags: - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts script: - bash builder/build-package ubuntu focal; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_ubuntu_jammy: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package ubuntu jammy; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_ubuntu_jammy_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package ubuntu jammy; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_ubuntu_noble: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package ubuntu noble; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_ubuntu_noble_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package ubuntu noble; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_debian_bullseye: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package debian bullseye; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_debian_bullseye_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package debian bullseye; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - - -build_debian_bookworm: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package debian bookworm; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_debian_bookworm_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package debian bookworm; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_kali_rolling: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package kali kali-rolling; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_kali_rolling_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package kali kali-rolling; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_oracle_8: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package oracle 8; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_oracle_8_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package oracle 8; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_oracle_9: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package oracle 9; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_oracle_9_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package oracle 9; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_opensuse_15: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package opensuse 15; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_opensuse_15_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package opensuse 15; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_thirtynine: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora thirtynine; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_thirtynine_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora thirtynine; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_forty: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora forty; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_forty_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora forty; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_fortyone: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora fortyone; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_fortyone_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora fortyone; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - +# +#build_ubuntu_jammy: +# extends: +# - .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package ubuntu jammy; +# +#build_ubuntu_jammy_arm: +# extends: +# - .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package ubuntu jammy; +# +#build_ubuntu_noble: +# extends: +# - .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package ubuntu noble; +# +#build_ubuntu_noble_arm: +# extends: +# - .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package ubuntu noble; +# +#build_debian_bullseye: +# extends: +# - .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package debian bullseye; +# +#build_debian_bullseye_arm: +# extends: +# - .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package debian bullseye; +# +#build_debian_bookworm: +# extends: +# - .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package debian bookworm; +# +#build_debian_bookworm_arm: +# extends: +# - .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package debian bookworm; +# +#build_kali_rolling: +# extends: +# - .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package kali kali-rolling; +# +#build_kali_rolling_arm: +# extends: +# - .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package kali kali-rolling; +# +#build_oracle_8: +# extends: +# - .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package oracle 8; +# +#build_oracle_8_arm: +# extends: +# - .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package oracle 8; +# +#build_oracle_9: +# extends: +# - .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package oracle 9; +# +#build_oracle_9_arm: +# extends: +# - .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package oracle 9; +# +#build_opensuse_15: +# extends: +# - .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package opensuse 15; +# +#build_opensuse_15_arm: +# extends: +# - .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package opensuse 15; +# +#build_fedora_thirtynine: +# extends: +# - .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package fedora thirtynine; +# +#build_fedora_thirtynine_arm: +# extends: +# - .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package fedora thirtynine; +# +#build_fedora_forty: +# extends: +# - .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package fedora forty; +# +#build_fedora_forty_arm: +# extends: +# - .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package fedora forty; +# +#build_fedora_fortyone: +# extends: +# - .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package fedora fortyone; +# +#build_fedora_fortyone_arm: +# extends: +# - .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package fedora fortyone; test: stage: test @@ -530,161 +279,67 @@ test: - oci-fixed-amd before_script: - *prepare_build + artifacts: + reports: + junit: SelfBench.xml script: - bash builder/test-vncserver - -build_alpine_318: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 318; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_318_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 318; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_319: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 319; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_319_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 319; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_320: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 320; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_320_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 320; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_321: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 321; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_321_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 321; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ +#build_alpine_318: +# extends: .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package alpine 318; +# +#build_alpine_318_arm: +# extends: .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package alpine 318; +# +#build_alpine_319: +# extends: .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package alpine 319; +# +#build_alpine_319_arm: +# extends: .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package alpine 319; +# +#build_alpine_320: +# extends: .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package alpine 320; +# +#build_alpine_320_arm: +# extends: .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package alpine 320; +# +#build_alpine_321: +# extends: .base_build +# tags: +# - oci-fixed-amd +# script: +# - bash builder/build-package alpine 321; +# +#build_alpine_321_arm: +# extends: .base_build +# tags: +# - oci-fixed-arm +# script: +# - bash builder/build-package alpine 321; upload: stage: upload @@ -700,33 +355,33 @@ upload: - prepare_to_run_scripts_and_s3_uploads - S3_CRASHPAD_BUILD_DIRECTORY="kasmvnc/crashpad/${CI_COMMIT_SHA}" - for dbgsym_package in `find output/ -type f -name '*dbgsym*deb'`; do - deb_package=$(find_deb_package "$dbgsym_package"); - xvnc_md5sum=$(fetch_xvnc_md5sum "$deb_package"); - upload_filename="${S3_CRASHPAD_BUILD_DIRECTORY}/${xvnc_md5sum}/kasmvncserver-dbgsym.deb"; - echo; - echo "File to upload $upload_filename"; - upload_to_s3 "$dbgsym_package" "$upload_filename" "$S3_BUCKET"; - rm "$dbgsym_package"; + deb_package=$(find_deb_package "$dbgsym_package"); + xvnc_md5sum=$(fetch_xvnc_md5sum "$deb_package"); + upload_filename="${S3_CRASHPAD_BUILD_DIRECTORY}/${xvnc_md5sum}/kasmvncserver-dbgsym.deb"; + echo; + echo "File to upload $upload_filename"; + upload_to_s3 "$dbgsym_package" "$upload_filename" "$S3_BUCKET"; + rm "$dbgsym_package"; done - export S3_BUILD_DIRECTORY="kasmvnc/${CI_COMMIT_SHA}" - export RELEASE_VERSION=$(.ci/next_release_version "$CI_COMMIT_REF_NAME") - uploaded_files=() - for package in `find output/ -type f -name '*.deb' -or -name '*.rpm' -or -name '*.apk'`; do - prepare_upload_filename "$package"; - upload_filename="${S3_BUILD_DIRECTORY}/$upload_filename"; - echo; - echo "File to upload $upload_filename"; - upload_to_s3 "$package" "$upload_filename" "$S3_BUCKET"; - UPLOAD_NAME=$(basename $upload_filename | sed 's#kasmvncserver_##' | sed -r 's#_([0-9]{1,3}\.){2}[0-9]{1,2}_\S+?([a-f0-9]{6})##' | sed -r 's#\.(deb|rpm|tgz)##'); - curl --request POST --header "PRIVATE-TOKEN:${GITLAB_API_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/statuses/${CI_COMMIT_SHA}?state=success&name=${UPLOAD_NAME}&target_url=${S3_URL}"; - uploaded_files+=("$upload_filename"); + prepare_upload_filename "$package"; + upload_filename="${S3_BUILD_DIRECTORY}/$upload_filename"; + echo; + echo "File to upload $upload_filename"; + upload_to_s3 "$package" "$upload_filename" "$S3_BUCKET"; + UPLOAD_NAME=$(basename $upload_filename | sed 's#kasmvncserver_##' | sed -r 's#_([0-9]{1,3}\.){2}[0-9]{1,2}_\S+?([a-f0-9]{6})##' | sed -r 's#\.(deb|rpm|tgz)##'); + curl --request POST --header "PRIVATE-TOKEN:${GITLAB_API_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/statuses/${CI_COMMIT_SHA}?state=success&name=${UPLOAD_NAME}&target_url=${S3_URL}"; + uploaded_files+=("$upload_filename"); done - make_index_html "${uploaded_files[@]}" > output/index.html; upload_build_preview: stage: upload - needs: ["upload"] - dependencies: ["upload"] + needs: [ "upload" ] + dependencies: [ "upload" ] image: ubuntu:focal tags: - oci-fixed-amd diff --git a/spec/helper/spec_helper.py b/spec/helper/spec_helper.py index cb12c9f..3079296 100644 --- a/spec/helper/spec_helper.py +++ b/spec/helper/spec_helper.py @@ -23,6 +23,18 @@ def write_config(config_text): f.write(config_text) +def clean_locks(): + tmp = '/tmp' + temporary_lock_file = os.path.join(tmp, '.X1-lock') + if (os.path.exists(temporary_lock_file)): + os.remove(temporary_lock_file) + + temporary_lock_file = os.path.join(tmp, '.X11-unix') + temporary_lock_file = os.path.join(temporary_lock_file, 'X1') + if (os.path.exists(temporary_lock_file)): + os.remove(temporary_lock_file) + + def clean_env(): clean_kasm_users() @@ -30,6 +42,7 @@ def clean_env(): vnc_dir = os.path.join(home_dir, ".vnc") Path(vnc_dir).rmtree(ignore_errors=True) + clean_locks() def clean_kasm_users(): home_dir = os.environ['HOME'] diff --git a/spec/vncserver_benchmarking_spec.py b/spec/vncserver_benchmarking_spec.py new file mode 100644 index 0000000..1cb59b1 --- /dev/null +++ b/spec/vncserver_benchmarking_spec.py @@ -0,0 +1,12 @@ +from mamba import description, context, it, fit, before, after +from expects import expect, equal, contain, match +from helper.spec_helper import run_cmd, clean_env, kill_xvnc + +with description("Benchmarking"): + with before.each: + clean_env() + with after.each: + kill_xvnc() + with it("runs benchmarks"): + completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -selfBench") + expect(completed_process.returncode).to(equal(0)) From b5f3f44c5753e2a4dc06ffa1b385ee77a23d7f51 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 7 Apr 2025 17:14:07 +0500 Subject: [PATCH 119/167] KASM-6984 Refactor SelfBench XML generation and enhance benchmarking. Simplified XML structure by removing unnecessary elements and attributes. Added new fields to aggregate test case count, total time, and class name in the generated "SelfBench.xml" file. Ensures clearer benchmarking output and streamlined code. KASM-6984 Refactor SelfBench XML generation and enhance benchmarking. Simplified XML structure by removing unnecessary elements and attributes. Added new fields to aggregate test case count, total time, and class name in the generated --- common/rfb/SelfBench.cxx | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/common/rfb/SelfBench.cxx b/common/rfb/SelfBench.cxx index ca8e3fb..62c0cac 100644 --- a/common/rfb/SelfBench.cxx +++ b/common/rfb/SelfBench.cxx @@ -44,14 +44,10 @@ static constexpr uint32_t HEIGHT = 1200; void SelfBench() { tinyxml2::XMLDocument doc; - auto *root = doc.NewElement("testsuites"); - root->SetAttribute("name", "Benchmarking"); - - auto *test_suits = doc.InsertFirstChild(root); - - auto *test_suit = doc.NewElement("testsuit"); + auto *test_suit = doc.NewElement("testsuite"); test_suit->SetAttribute("name", "SelfBench"); - test_suits->InsertEndChild(test_suit); + + doc.InsertFirstChild(test_suit); ManagedPixelBuffer f1(pfRGBX, WIDTH, HEIGHT); ManagedPixelBuffer f2(pfRGBX, WIDTH, HEIGHT); @@ -85,18 +81,26 @@ void SelfBench() { TightJPEGEncoder jpeg(nullptr); - auto benchmark = [&doc, &test_suit](const char *name, uint32_t runs, auto func) { + uint32_t test_cases {}; + uint64_t total_time {}; + + auto benchmark = [&doc, &test_suit, &test_cases, &total_time](const char *name, uint32_t runs, auto func) { auto now = std::chrono::high_resolution_clock::now(); for (uint32_t i = 0; i < runs; i++) { func(i); } + ++test_cases; auto value = elapsedMs(now); + double junit_value = value / 1000.; + total_time += value; + vlog.info("%s took %lu ms (%u runs)", name, value, runs); auto *test_case = doc.NewElement("testcase"); test_case->SetAttribute("name", name); - test_case->SetAttribute("time", value); + test_case->SetAttribute("time", junit_value); test_case->SetAttribute("runs", runs); + test_case->SetAttribute("classname", "KasmVNC"); test_suit->InsertEndChild(test_case); }; @@ -180,6 +184,10 @@ void SelfBench() { comparer->compare(false, cursorReg); }); + test_suit->SetAttribute("tests", test_cases); + test_suit->SetAttribute("failures", 0); + test_suit->SetAttribute("time", total_time); + doc.SaveFile("SelfBench.xml"); exit(0); From 969996a6470b52ad5149d66fc4b3128fbb844cdd Mon Sep 17 00:00:00 2001 From: El Date: Mon, 7 Apr 2025 18:56:24 +0500 Subject: [PATCH 120/167] KASM-6984 Add extende benchmark parameter to Server class Introduce a new "benchmark" boolean parameter in the Server class to enable extended benchmarking functionality. This complements the existing self-benchmark feature, providing more comprehensive performance testing options. --- common/rfb/ServerCore.cxx | 4 ++ common/rfb/ServerCore.h | 133 +++++++++++++++++++------------------- 2 files changed, 69 insertions(+), 68 deletions(-) diff --git a/common/rfb/ServerCore.cxx b/common/rfb/ServerCore.cxx index 3881693..97aa875 100644 --- a/common/rfb/ServerCore.cxx +++ b/common/rfb/ServerCore.cxx @@ -117,6 +117,10 @@ rfb::BoolParameter rfb::Server::selfBench ("SelfBench", "Run self-benchmarks and exit.", false); +rfb::BoolParameter rfb::Server::benchmark ( + "Benchmark", + "Run extended benchmarks and exit.", + false); rfb::IntParameter rfb::Server::dynamicQualityMin ("DynamicQualityMin", "The minimum dynamic JPEG quality, 0 = low, 9 = high", diff --git a/common/rfb/ServerCore.h b/common/rfb/ServerCore.h index c3a53e5..aeae07f 100644 --- a/common/rfb/ServerCore.h +++ b/common/rfb/ServerCore.h @@ -28,73 +28,70 @@ #include namespace rfb { - - class Server { - public: - - static IntParameter idleTimeout; - static IntParameter maxDisconnectionTime; - static IntParameter maxConnectionTime; - static IntParameter maxIdleTime; - static IntParameter clientWaitTimeMillis; - static IntParameter compareFB; - static IntParameter frameRate; - static IntParameter dynamicQualityMin; - static IntParameter dynamicQualityMax; - static IntParameter treatLossless; - static IntParameter scrollDetectLimit; - static IntParameter rectThreads; - static IntParameter DLP_ClipSendMax; - static IntParameter DLP_ClipAcceptMax; - static IntParameter DLP_ClipDelay; - static IntParameter DLP_KeyRateLimit; - static IntParameter DLP_WatermarkRepeatSpace; - static IntParameter DLP_WatermarkFontSize; - static IntParameter DLP_WatermarkTimeOffset; - static IntParameter DLP_WatermarkTimeOffsetMinutes; - static IntParameter DLP_WatermarkTextAngle; - static StringParameter DLP_ClipLog; - static StringParameter DLP_Region; - static StringParameter DLP_Clip_Types; - static StringParameter DLP_WatermarkImage; - static StringParameter DLP_WatermarkLocation; - static StringParameter DLP_WatermarkTint; - static StringParameter DLP_WatermarkText; - static StringParameter DLP_WatermarkFont; - static BoolParameter DLP_RegionAllowClick; - static BoolParameter DLP_RegionAllowRelease; - static IntParameter jpegVideoQuality; - static IntParameter webpVideoQuality; - static StringParameter maxVideoResolution; - static IntParameter videoTime; - static IntParameter videoOutTime; - static IntParameter videoArea; - static IntParameter videoScaling; - static IntParameter udpFullFrameFrequency; - static IntParameter udpPort; - static StringParameter kasmPasswordFile; - static StringParameter publicIP; - static StringParameter stunServer; - static BoolParameter printVideoArea; - static BoolParameter protocol3_3; - static BoolParameter alwaysShared; - static BoolParameter neverShared; - static BoolParameter disconnectClients; - static BoolParameter acceptKeyEvents; - static BoolParameter acceptPointerEvents; - static BoolParameter acceptCutText; - static BoolParameter sendCutText; - static BoolParameter acceptSetDesktopSize; - static BoolParameter queryConnect; - static BoolParameter detectScrolling; - static BoolParameter detectHorizontal; - static BoolParameter ignoreClientSettingsKasm; - static BoolParameter selfBench; - static PresetParameter preferBandwidth; - static IntParameter webpEncodingTime; - }; - + class Server { + public: + static IntParameter idleTimeout; + static IntParameter maxDisconnectionTime; + static IntParameter maxConnectionTime; + static IntParameter maxIdleTime; + static IntParameter clientWaitTimeMillis; + static IntParameter compareFB; + static IntParameter frameRate; + static IntParameter dynamicQualityMin; + static IntParameter dynamicQualityMax; + static IntParameter treatLossless; + static IntParameter scrollDetectLimit; + static IntParameter rectThreads; + static IntParameter DLP_ClipSendMax; + static IntParameter DLP_ClipAcceptMax; + static IntParameter DLP_ClipDelay; + static IntParameter DLP_KeyRateLimit; + static IntParameter DLP_WatermarkRepeatSpace; + static IntParameter DLP_WatermarkFontSize; + static IntParameter DLP_WatermarkTimeOffset; + static IntParameter DLP_WatermarkTimeOffsetMinutes; + static IntParameter DLP_WatermarkTextAngle; + static StringParameter DLP_ClipLog; + static StringParameter DLP_Region; + static StringParameter DLP_Clip_Types; + static StringParameter DLP_WatermarkImage; + static StringParameter DLP_WatermarkLocation; + static StringParameter DLP_WatermarkTint; + static StringParameter DLP_WatermarkText; + static StringParameter DLP_WatermarkFont; + static BoolParameter DLP_RegionAllowClick; + static BoolParameter DLP_RegionAllowRelease; + static IntParameter jpegVideoQuality; + static IntParameter webpVideoQuality; + static StringParameter maxVideoResolution; + static IntParameter videoTime; + static IntParameter videoOutTime; + static IntParameter videoArea; + static IntParameter videoScaling; + static IntParameter udpFullFrameFrequency; + static IntParameter udpPort; + static StringParameter kasmPasswordFile; + static StringParameter publicIP; + static StringParameter stunServer; + static BoolParameter printVideoArea; + static BoolParameter protocol3_3; + static BoolParameter alwaysShared; + static BoolParameter neverShared; + static BoolParameter disconnectClients; + static BoolParameter acceptKeyEvents; + static BoolParameter acceptPointerEvents; + static BoolParameter acceptCutText; + static BoolParameter sendCutText; + static BoolParameter acceptSetDesktopSize; + static BoolParameter queryConnect; + static BoolParameter detectScrolling; + static BoolParameter detectHorizontal; + static BoolParameter ignoreClientSettingsKasm; + static BoolParameter selfBench; + static BoolParameter benchmark; + static PresetParameter preferBandwidth; + static IntParameter webpEncodingTime; + }; }; -#endif // __RFB_SERVER_CORE_H__ - +#endif // __RFB_SERVER_CORE_H__ \ No newline at end of file From 4983bb8be559d32a0a3b1dba055a314fc4db2520 Mon Sep 17 00:00:00 2001 From: El Date: Tue, 8 Apr 2025 04:44:57 +0500 Subject: [PATCH 121/167] KASM-6984 Add benchmark utility with FFmpeg integration for video handling --- common/CMakeLists.txt | 8 +-- common/rfb/CMakeLists.txt | 12 +++- common/rfb/VNCServerST.cxx | 20 +++++-- common/rfb/benchmark.cxx | 115 +++++++++++++++++++++++++++++++++++++ common/rfb/benchmark.h | 102 ++++++++++++++++++++++++++++++++ 5 files changed, 246 insertions(+), 11 deletions(-) create mode 100644 common/rfb/benchmark.cxx create mode 100644 common/rfb/benchmark.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index e4489f6..1fbdc22 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -9,7 +9,7 @@ add_subdirectory(rfb) # because PIC code does not exist on that platform and MinGW complains if -fPIC # is passed (additionally, libvnc is not used on Windows.) -if(NOT WIN32) - set_target_properties(os rdr network Xregion rfb - PROPERTIES COMPILE_FLAGS -fPIC) -endif() +if (NOT WIN32) + set_target_properties(os rdr network Xregion rfb + PROPERTIES COMPILE_FLAGS -fPIC) +endif () diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt index 56f4488..a99e548 100644 --- a/common/rfb/CMakeLists.txt +++ b/common/rfb/CMakeLists.txt @@ -1,4 +1,5 @@ set(RFB_SOURCES + benchmark.cxx Blacklist.cxx Congestion.cxx CConnection.cxx @@ -87,7 +88,9 @@ if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_ endif () if (HAVE_PAM) - set(RFB_SOURCES ${RFB_SOURCES} UnixPasswordValidator.cxx + set(RFB_SOURCES + ${RFB_SOURCES} + UnixPasswordValidator.cxx UnixPasswordValidator.h pam.c pam.h) set(RFB_LIBRARIES ${RFB_LIBRARIES} ${PAM_LIBS}) endif () @@ -122,9 +125,14 @@ else () set(RFB_SOURCES ${RFB_SOURCES} ${SCALE_DUMMY_SOURCES} + benchmark.h ) endif () +find_package(PkgConfig REQUIRED) + +pkg_check_modules(FFMPEG REQUIRED libavcodec libavformat libavutil libswscale) + add_library(rfb STATIC ${RFB_SOURCES}) target_include_directories(rfb PRIVATE @@ -135,7 +143,7 @@ target_include_directories(rfb PRIVATE ${CMAKE_SOURCE_DIR}/third_party/tinyxml2 ) -target_link_libraries(rfb PRIVATE ${RFB_LIBRARIES} tinyxml2_objs) +target_link_libraries(rfb PRIVATE ${RFB_LIBRARIES} tinyxml2_objs ${FFMPEG_LIBRARIES}) if (UNIX) libtool_create_control_file(rfb) diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index a84ebc9..35d5e5c 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -73,6 +73,7 @@ #include #include #include +#include using namespace rfb; @@ -82,6 +83,8 @@ EncCache VNCServerST::encCache; void SelfBench(); +void benchmark(const std::string&); + // // -=- VNCServerST Implementation // @@ -126,7 +129,7 @@ static void parseRegionPart(const bool percents, rdr::U16 &pcdest, int &dest, *inptr = ptr; } -VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) +VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_, bool a) : blHosts(&blacklist), desktop(desktop_), desktopStarted(false), blockCounter(0), pb(0), blackedpb(0), ledState(ledUnknown), name(strDup(name_)), pointerClient(0), clipboardClient(0), @@ -223,11 +226,18 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) trackingClient[0] = 0; - if (watermarkData) - sendWatermark = true; + if (watermarkData) + sendWatermark = true; - if (Server::selfBench) - SelfBench(); + if (Server::selfBench) + SelfBench(); + + if (Server::benchmark) { + auto *file_name = Server::benchmark.getValueStr(); + if (std::filesystem::exists(file_name)) + throw Exception("Benchmarking video file does not exist"); + benchmark(file_name); + } } VNCServerST::~VNCServerST() diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx new file mode 100644 index 0000000..ce0019a --- /dev/null +++ b/common/rfb/benchmark.cxx @@ -0,0 +1,115 @@ +/* Copyright (C) 2025 Kasm Web +* + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ + +#include "benchmark.h" +#include +#include +#include +#include "VNCServer.h" + +static rfb::LogWriter vlog("Benchmarking"); + +void benchmark(const std::string &path) { + AVFormatContext *format_ctx = nullptr; + if (avformat_open_input(&format_ctx, path.c_str(), nullptr, nullptr) < 0) + throw std::runtime_error("Could not open video file"); + + FormatCtxGuard format_ctx_guard{format_ctx}; + + // Find stream info + if (avformat_find_stream_info(format_ctx, nullptr) < 0) + throw std::runtime_error("Could not find stream info"); + + // Find video stream + int video_stream_idx = -1; + for (uint32_t i = 0; i < format_ctx->nb_streams; ++i) { + if (format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + video_stream_idx = static_cast(i); + break; + } + } + + if (video_stream_idx == -1) + throw std::runtime_error("No video stream found"); + + // Get codec parameters and decoder + const auto *codec_parameters = format_ctx->streams[video_stream_idx]->codecpar; + const auto *codec = avcodec_find_decoder(codec_parameters->codec_id); + if (!codec) + throw std::runtime_error("Codec not found"); + + CodecCtxGuard codex_ctx_guard{avcodec_alloc_context3(codec)}; + auto *codec_ctx = codex_ctx_guard.get(); + + if (!codec_ctx || avcodec_parameters_to_context(codec_ctx, codec_parameters) < 0) + throw std::runtime_error("Failed to set up codec context"); + + if (avcodec_open2(codec_ctx, codec, nullptr) < 0) + throw std::runtime_error("Could not open codec"); + + // Allocate frame and packet + FrameGuard frame_guard{av_frame_alloc()}; + auto *frame = frame_guard.get(); + + PacketGuard packet_guard{av_packet_alloc()}; + auto *packet = packet_guard.get(); + + if (!frame || !packet) + throw std::runtime_error("Could not allocate frame or packet"); + + // Scaling context to convert to RGB24 + SwsContext *sws_ctx = sws_getContext( + codec_ctx->width, codec_ctx->height, codec_ctx->pix_fmt, + codec_ctx->width, codec_ctx->height, AV_PIX_FMT_RGB24, + SWS_BILINEAR, nullptr, nullptr, nullptr + ); + + if (!sws_ctx) + throw std::runtime_error("Could not create scaling context"); + + SwsContextGuard sws_ctx_guard{sws_ctx}; + + FrameGuard rgb_frame_guard{av_frame_alloc()}; + auto *rgb_frame = rgb_frame_guard.get(); + + if (!rgb_frame) + throw std::runtime_error("Could not allocate frame"); + + rgb_frame->format = AV_PIX_FMT_RGB24; + rgb_frame->width = codec_ctx->width; + rgb_frame->height = codec_ctx->height; + + if (av_frame_get_buffer(rgb_frame, 0) != 0) + throw std::runtime_error("Could not allocate frame data"); + + while (av_read_frame(format_ctx, packet) == 0) { + if (packet->stream_index == video_stream_idx) { + if (avcodec_send_packet(codec_ctx, packet) == 0) { + while (avcodec_receive_frame(codec_ctx, frame) == 0) { + // Convert to RGB + sws_scale(sws_ctx, frame->data, frame->linesize, 0, frame->height, + rgb_frame->data, rgb_frame->linesize); + + // Save as BMP + // saveFrameAsBMP(rgb_frame, ++frameNumber); + } + } + } + av_packet_unref(packet); + } +} diff --git a/common/rfb/benchmark.h b/common/rfb/benchmark.h new file mode 100644 index 0000000..61edae5 --- /dev/null +++ b/common/rfb/benchmark.h @@ -0,0 +1,102 @@ +/* Copyright (C) 2025 Kasm Web +* + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ + +#pragma once + +#include "Timer.h" +#include +#include + +extern "C" { +#include +#include +#include +} + +struct AVFormatContextDeleter { + void operator()(AVFormatContext *ctx) const { + avformat_close_input(&ctx); + } +}; + +struct AVCodecContextDeleter { + void operator()(AVCodecContext *ctx) const { + avcodec_free_context(&ctx); + } +}; + +struct AVFrameDeleter { + void operator()(AVFrame *frame) const { + av_frame_free(&frame); + } +}; + +struct SwsContextDeleter { + void operator()(SwsContext *ctx) const { + sws_freeContext(ctx); + } +}; + +struct PacketDeleter { + void operator()(AVPacket *packet) const { + av_packet_free(&packet); + } +}; + +using FormatCtxGuard = std::unique_ptr; +using CodecCtxGuard = std::unique_ptr; +using FrameGuard = std::unique_ptr; +using SwsContextGuard = std::unique_ptr; +using PacketGuard = std::unique_ptr; + +namespace rfb { + class BenchmarkServer : public VNCServer, public Timer::Callback { + public: + bool handleTimeout(Timer *t) override; + + void add_changed(const Region ®ion) override; + + void add_copied(const Region &dest, const Point &delta) override; + + void blockUpdates() override; + + void unblockUpdates() override; + + void setPixelBuffer(PixelBuffer *pb, const ScreenSet &layout) override; + + void setPixelBuffer(PixelBuffer *pb) override; + + void setScreenLayout(const ScreenSet &layout) override; + + [[nodiscard]] PixelBuffer *getPixelBuffer() const override; + + void announceClipboard(bool available) override; + + void bell() override; + + void closeClients(const char *reason) override; + + void setCursor(int width, int height, const Point &hotspot, const rdr::U8 *cursorData, bool resizing) override; + + void setCursorPos(const Point &p, bool warped) override; + + void setName(const char *name) override; + + void setLEDState(unsigned state) override; + }; +} From 9464071aa00bf3dffb75fc7f9ce3463401865d2e Mon Sep 17 00:00:00 2001 From: El Date: Wed, 9 Apr 2025 13:30:42 +0500 Subject: [PATCH 122/167] KASM-6984 Wrap tests in conditionals --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a509b4..8ba357c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,12 +239,12 @@ else() endif() if(ENABLE_NLS) - add_subdirectory(po) + add_subdirectory(po) endif() if (TESTS) - add_subdirectory(tests) -endif () + add_subdirectory(tests) +endif() include(cmake/BuildPackages.cmake) From 7db59bdec9d5ca276fd07aef1d7608b1927442f6 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 10 Apr 2025 14:08:54 +0500 Subject: [PATCH 123/167] KASM-6984 Update Dockerfile to include FFmpeg libraries --- builder/dockerfile.ubuntu_jammy.dev | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builder/dockerfile.ubuntu_jammy.dev b/builder/dockerfile.ubuntu_jammy.dev index 7201cf2..255e3c7 100644 --- a/builder/dockerfile.ubuntu_jammy.dev +++ b/builder/dockerfile.ubuntu_jammy.dev @@ -32,7 +32,9 @@ RUN sed -i 's$# deb-src$deb-src$' /etc/apt/sources.list && \ libpng-dev \ libtiff-dev \ libgif-dev \ + libavformat-dev \ libavcodec-dev \ + libswscale-dev \ libssl-dev \ libxrandr-dev \ libxcursor-dev \ @@ -61,7 +63,7 @@ COPY builder/common.sh /tmp RUN chmod +x /tmp/build-webp && /tmp/build-webp RUN chmod +x /tmp/build-libjpeg-turbo && /tmp/build-libjpeg-turbo - + USER 1000 WORKDIR /src From 04e60f167174b6f75793bc5b5ea6174ce08033ec Mon Sep 17 00:00:00 2001 From: El Date: Thu, 10 Apr 2025 14:10:53 +0500 Subject: [PATCH 124/167] KASM-6984 Use modern C++ idioms and fix member initialization --- common/rfb/VNCSConnectionST.cxx | 2 +- common/rfb/VNCServerST.cxx | 4 ++-- common/rfb/VNCServerST.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index c470de7..ed36bdc 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -62,7 +62,7 @@ VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s, losslessTimer(this), kbdLogTimer(this), binclipTimer(this), server(server_), updates(false), updateRenderedCursor(false), removeRenderedCursor(false), - continuousUpdates(false), encodeManager(this, &server_->encCache), + continuousUpdates(false), encodeManager(this, &VNCServerST::encCache), needsPermCheck(false), pointerEventTime(0), clientHasCursor(false), accessRights(AccessDefault), startTime(time(0)), frameTracking(false), diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index 35d5e5c..4106125 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -129,7 +129,7 @@ static void parseRegionPart(const bool percents, rdr::U16 &pcdest, int &dest, *inptr = ptr; } -VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_, bool a) +VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) : blHosts(&blacklist), desktop(desktop_), desktopStarted(false), blockCounter(0), pb(0), blackedpb(0), ledState(ledUnknown), name(strDup(name_)), pointerClient(0), clipboardClient(0), @@ -201,7 +201,7 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_, bool a) } } - DLPRegion.enabled = 1; + DLPRegion.enabled = true; } kasmpasswdpath[0] = '\0'; diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h index 721e028..fee2517 100644 --- a/common/rfb/VNCServerST.h +++ b/common/rfb/VNCServerST.h @@ -148,7 +148,7 @@ namespace rfb { // the connection. enum queryResult { ACCEPT, REJECT, PENDING }; struct QueryConnectionHandler { - virtual ~QueryConnectionHandler() {} + virtual ~QueryConnectionHandler() = default; virtual queryResult queryConnection(network::Socket* sock, const char* userName, char** reason) = 0; From 4315f7d4467e40a68cce8513e1bc25c2ddb89a54 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 10 Apr 2025 14:13:51 +0500 Subject: [PATCH 125/167] KASM-6984 Update test job tags in .gitlab-ci.yml --- .gitlab-ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e104a69..7804399 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -276,13 +276,15 @@ build_ubuntu_focal_arm: test: stage: test tags: - - oci-fixed-amd + - kasmvnc-x86 before_script: - *prepare_build artifacts: reports: junit: SelfBench.xml script: + - bash wget https://kasmweb-build-artifacts.s3.us-east-1.amazonaws.com/kasmvnc/static/127072-737747495_small.mp4 + - bash ls -l - bash builder/test-vncserver #build_alpine_318: From 1495f7151bd74b98c02d3a0d5f317a105c0e14a9 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 10 Apr 2025 15:06:30 +0500 Subject: [PATCH 126/167] KASM-6984 Added new dependencies: libavformat-dev and libswscale-dev --- builder/dockerfile.ubuntu_focal.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builder/dockerfile.ubuntu_focal.build b/builder/dockerfile.ubuntu_focal.build index 03f5253..57c7373 100644 --- a/builder/dockerfile.ubuntu_focal.build +++ b/builder/dockerfile.ubuntu_focal.build @@ -13,7 +13,8 @@ RUN apt-get update && \ RUN apt-get update && apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev RUN apt-get update && apt-get -y install ninja-build nasm git vim wget curl -RUN apt-get update && apt-get -y install libtbb-dev libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev +RUN apt-get update && apt-get -y install libtbb-dev libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev \ + libxcursor-dev libavformat-dev libswscale-dev ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR From 5287c44e54816bdbaf36bc44c06b5289a139836a Mon Sep 17 00:00:00 2001 From: El Date: Mon, 31 Mar 2025 07:46:07 +0500 Subject: [PATCH 127/167] KASM-6984 Refactor GitLab CI to utilize job extensions and reduce redundancy --- .gitlab-ci.yml | 872 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 610 insertions(+), 262 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7804399..4017934 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -66,14 +66,18 @@ build_www: paths: - output/ -.base_build: +build_ubuntu_focal: stage: build allow_failure: true + tags: + - oci-fixed-amd before_script: - *prepare_build - *prepare_www after_script: - *prepare_artfacts + script: + - bash builder/build-package ubuntu focal; only: variables: - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME @@ -81,197 +85,444 @@ build_www: paths: - output/ -build_ubuntu_focal: - extends: - - .base_build - tags: - - oci-fixed-amd - script: - - bash builder/build-package ubuntu focal; - build_ubuntu_focal_arm: - extends: - - .base_build + stage: build + allow_failure: true tags: - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts script: - bash builder/build-package ubuntu focal; -# -#build_ubuntu_jammy: -# extends: -# - .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package ubuntu jammy; -# -#build_ubuntu_jammy_arm: -# extends: -# - .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package ubuntu jammy; -# -#build_ubuntu_noble: -# extends: -# - .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package ubuntu noble; -# -#build_ubuntu_noble_arm: -# extends: -# - .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package ubuntu noble; -# -#build_debian_bullseye: -# extends: -# - .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package debian bullseye; -# -#build_debian_bullseye_arm: -# extends: -# - .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package debian bullseye; -# -#build_debian_bookworm: -# extends: -# - .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package debian bookworm; -# -#build_debian_bookworm_arm: -# extends: -# - .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package debian bookworm; -# -#build_kali_rolling: -# extends: -# - .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package kali kali-rolling; -# -#build_kali_rolling_arm: -# extends: -# - .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package kali kali-rolling; -# -#build_oracle_8: -# extends: -# - .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package oracle 8; -# -#build_oracle_8_arm: -# extends: -# - .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package oracle 8; -# -#build_oracle_9: -# extends: -# - .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package oracle 9; -# -#build_oracle_9_arm: -# extends: -# - .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package oracle 9; -# -#build_opensuse_15: -# extends: -# - .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package opensuse 15; -# -#build_opensuse_15_arm: -# extends: -# - .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package opensuse 15; -# -#build_fedora_thirtynine: -# extends: -# - .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package fedora thirtynine; -# -#build_fedora_thirtynine_arm: -# extends: -# - .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package fedora thirtynine; -# -#build_fedora_forty: -# extends: -# - .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package fedora forty; -# -#build_fedora_forty_arm: -# extends: -# - .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package fedora forty; -# -#build_fedora_fortyone: -# extends: -# - .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package fedora fortyone; -# -#build_fedora_fortyone_arm: -# extends: -# - .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package fedora fortyone; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_ubuntu_jammy: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package ubuntu jammy; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_ubuntu_jammy_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package ubuntu jammy; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_ubuntu_noble: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package ubuntu noble; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_ubuntu_noble_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package ubuntu noble; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_debian_bullseye: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package debian bullseye; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_debian_bullseye_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package debian bullseye; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + + +build_debian_bookworm: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package debian bookworm; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_debian_bookworm_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package debian bookworm; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_kali_rolling: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package kali kali-rolling; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_kali_rolling_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package kali kali-rolling; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_oracle_8: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package oracle 8; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_oracle_8_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package oracle 8; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_oracle_9: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package oracle 9; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_oracle_9_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package oracle 9; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_opensuse_15: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package opensuse 15; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_opensuse_15_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package opensuse 15; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_fedora_thirtynine: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package fedora thirtynine; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_fedora_thirtynine_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package fedora thirtynine; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_fedora_forty: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package fedora forty; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_fedora_forty_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package fedora forty; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_fedora_fortyone: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package fedora fortyone; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_fedora_fortyone_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package fedora fortyone; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + test: stage: test @@ -281,67 +532,164 @@ test: - *prepare_build artifacts: reports: - junit: SelfBench.xml + junit: + - SelfBench.xml + - Benchmark.xml script: - - bash wget https://kasmweb-build-artifacts.s3.us-east-1.amazonaws.com/kasmvnc/static/127072-737747495_small.mp4 - - bash ls -l - bash builder/test-vncserver -#build_alpine_318: -# extends: .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package alpine 318; -# -#build_alpine_318_arm: -# extends: .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package alpine 318; -# -#build_alpine_319: -# extends: .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package alpine 319; -# -#build_alpine_319_arm: -# extends: .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package alpine 319; -# -#build_alpine_320: -# extends: .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package alpine 320; -# -#build_alpine_320_arm: -# extends: .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package alpine 320; -# -#build_alpine_321: -# extends: .base_build -# tags: -# - oci-fixed-amd -# script: -# - bash builder/build-package alpine 321; -# -#build_alpine_321_arm: -# extends: .base_build -# tags: -# - oci-fixed-arm -# script: -# - bash builder/build-package alpine 321; + +build_alpine_318: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package alpine 318; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_alpine_318_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package alpine 318; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_alpine_319: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package alpine 319; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_alpine_319_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package alpine 319; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_alpine_320: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package alpine 320; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_alpine_320_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package alpine 320; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_alpine_321: + stage: build + allow_failure: true + tags: + - oci-fixed-amd + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package alpine 321; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ + +build_alpine_321_arm: + stage: build + allow_failure: true + tags: + - oci-fixed-arm + before_script: + - *prepare_build + - *prepare_www + after_script: + - *prepare_artfacts + script: + - bash builder/build-package alpine 321; + only: + variables: + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + artifacts: + paths: + - output/ upload: stage: upload @@ -357,33 +705,33 @@ upload: - prepare_to_run_scripts_and_s3_uploads - S3_CRASHPAD_BUILD_DIRECTORY="kasmvnc/crashpad/${CI_COMMIT_SHA}" - for dbgsym_package in `find output/ -type f -name '*dbgsym*deb'`; do - deb_package=$(find_deb_package "$dbgsym_package"); - xvnc_md5sum=$(fetch_xvnc_md5sum "$deb_package"); - upload_filename="${S3_CRASHPAD_BUILD_DIRECTORY}/${xvnc_md5sum}/kasmvncserver-dbgsym.deb"; - echo; - echo "File to upload $upload_filename"; - upload_to_s3 "$dbgsym_package" "$upload_filename" "$S3_BUCKET"; - rm "$dbgsym_package"; + deb_package=$(find_deb_package "$dbgsym_package"); + xvnc_md5sum=$(fetch_xvnc_md5sum "$deb_package"); + upload_filename="${S3_CRASHPAD_BUILD_DIRECTORY}/${xvnc_md5sum}/kasmvncserver-dbgsym.deb"; + echo; + echo "File to upload $upload_filename"; + upload_to_s3 "$dbgsym_package" "$upload_filename" "$S3_BUCKET"; + rm "$dbgsym_package"; done - export S3_BUILD_DIRECTORY="kasmvnc/${CI_COMMIT_SHA}" - export RELEASE_VERSION=$(.ci/next_release_version "$CI_COMMIT_REF_NAME") - uploaded_files=() - for package in `find output/ -type f -name '*.deb' -or -name '*.rpm' -or -name '*.apk'`; do - prepare_upload_filename "$package"; - upload_filename="${S3_BUILD_DIRECTORY}/$upload_filename"; - echo; - echo "File to upload $upload_filename"; - upload_to_s3 "$package" "$upload_filename" "$S3_BUCKET"; - UPLOAD_NAME=$(basename $upload_filename | sed 's#kasmvncserver_##' | sed -r 's#_([0-9]{1,3}\.){2}[0-9]{1,2}_\S+?([a-f0-9]{6})##' | sed -r 's#\.(deb|rpm|tgz)##'); - curl --request POST --header "PRIVATE-TOKEN:${GITLAB_API_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/statuses/${CI_COMMIT_SHA}?state=success&name=${UPLOAD_NAME}&target_url=${S3_URL}"; - uploaded_files+=("$upload_filename"); + prepare_upload_filename "$package"; + upload_filename="${S3_BUILD_DIRECTORY}/$upload_filename"; + echo; + echo "File to upload $upload_filename"; + upload_to_s3 "$package" "$upload_filename" "$S3_BUCKET"; + UPLOAD_NAME=$(basename $upload_filename | sed 's#kasmvncserver_##' | sed -r 's#_([0-9]{1,3}\.){2}[0-9]{1,2}_\S+?([a-f0-9]{6})##' | sed -r 's#\.(deb|rpm|tgz)##'); + curl --request POST --header "PRIVATE-TOKEN:${GITLAB_API_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/statuses/${CI_COMMIT_SHA}?state=success&name=${UPLOAD_NAME}&target_url=${S3_URL}"; + uploaded_files+=("$upload_filename"); done - make_index_html "${uploaded_files[@]}" > output/index.html; upload_build_preview: stage: upload - needs: [ "upload" ] - dependencies: [ "upload" ] + needs: ["upload"] + dependencies: ["upload"] image: ubuntu:focal tags: - oci-fixed-amd From 624cb28b5233bac832c29e9538aac47993d8b264 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 7 Apr 2025 18:56:24 +0500 Subject: [PATCH 128/167] KASM-6984 Add extended benchmark parameter to Server class Introduce a new "benchmark" boolean parameter in the Server class to enable extended benchmarking functionality. This complements the existing self-benchmark feature, providing more comprehensive performance testing options. --- common/rfb/ServerCore.cxx | 4 ++-- common/rfb/ServerCore.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/rfb/ServerCore.cxx b/common/rfb/ServerCore.cxx index 97aa875..0921665 100644 --- a/common/rfb/ServerCore.cxx +++ b/common/rfb/ServerCore.cxx @@ -117,10 +117,10 @@ rfb::BoolParameter rfb::Server::selfBench ("SelfBench", "Run self-benchmarks and exit.", false); -rfb::BoolParameter rfb::Server::benchmark ( +rfb::StringParameter rfb::Server::benchmark ( "Benchmark", "Run extended benchmarks and exit.", - false); + "video.mp4"); rfb::IntParameter rfb::Server::dynamicQualityMin ("DynamicQualityMin", "The minimum dynamic JPEG quality, 0 = low, 9 = high", diff --git a/common/rfb/ServerCore.h b/common/rfb/ServerCore.h index aeae07f..a64fc21 100644 --- a/common/rfb/ServerCore.h +++ b/common/rfb/ServerCore.h @@ -88,7 +88,7 @@ namespace rfb { static BoolParameter detectHorizontal; static BoolParameter ignoreClientSettingsKasm; static BoolParameter selfBench; - static BoolParameter benchmark; + static StringParameter benchmark; static PresetParameter preferBandwidth; static IntParameter webpEncodingTime; }; From f90db82efea55d53d5ceadf863d037cafbd6ac26 Mon Sep 17 00:00:00 2001 From: El Date: Tue, 8 Apr 2025 04:44:57 +0500 Subject: [PATCH 129/167] KASM-6984 Add benchmark utility with FFmpeg integration for video handling --- common/rfb/VNCServerST.cxx | 12 ++++++------ common/rfb/benchmark.cxx | 11 +++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index 4106125..b1ef22f 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -129,15 +129,15 @@ static void parseRegionPart(const bool percents, rdr::U16 &pcdest, int &dest, *inptr = ptr; } -VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) +VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_, bool a) : blHosts(&blacklist), desktop(desktop_), desktopStarted(false), - blockCounter(0), pb(0), blackedpb(0), ledState(ledUnknown), - name(strDup(name_)), pointerClient(0), clipboardClient(0), - comparer(0), cursor(new Cursor(0, 0, Point(), NULL)), + blockCounter(0), pb(nullptr), blackedpb(nullptr), ledState(ledUnknown), + name(strDup(name_)), pointerClient(nullptr), clipboardClient(nullptr), + comparer(nullptr), cursor(new Cursor(0, 0, Point(), nullptr)), renderedCursorInvalid(false), - queryConnectionHandler(0), keyRemapper(&KeyRemapper::defInstance), + queryConnectionHandler(nullptr), keyRemapper(&KeyRemapper::defInstance), lastConnectionTime(0), disableclients(false), - frameTimer(this), apimessager(NULL), trackingFrameStats(0), + frameTimer(this), apimessager(nullptr), trackingFrameStats(0), clipboardId(0), sendWatermark(false) { lastUserInputTime = lastDisconnectTime = time(0); diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index ce0019a..d80c2ed 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -94,6 +94,13 @@ void benchmark(const std::string &path) { rgb_frame->width = codec_ctx->width; rgb_frame->height = codec_ctx->height; + static const rfb::PixelFormat pf{32, 24, false, true, 0xFF, 0xFF, 0xFF, 0, 8, 16}; + const rfb::Rect rect{0, 0, rgb_frame->width, rgb_frame->height}; + + rfb::ManagedPixelBuffer pb{pf, rect.width(), rect.height()}; + + server->setPixelBuffer(&pb); + if (av_frame_get_buffer(rgb_frame, 0) != 0) throw std::runtime_error("Could not allocate frame data"); @@ -105,8 +112,8 @@ void benchmark(const std::string &path) { sws_scale(sws_ctx, frame->data, frame->linesize, 0, frame->height, rgb_frame->data, rgb_frame->linesize); - // Save as BMP - // saveFrameAsBMP(rgb_frame, ++frameNumber); + + pb.imageRect(rect, rgb_frame->data[0], rect.width()); } } } From 092d1cbdf5a523dde16afe793dacd16135a6bce5 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 10 Apr 2025 14:10:53 +0500 Subject: [PATCH 130/167] KASM-6984 Enhance benchmarking with detailed stats and desktop updates Use modern C++ idioms and fix member initialization --- common/rfb/ServerCore.cxx | 18 +-- common/rfb/VNCServerST.cxx | 6 +- common/rfb/benchmark.cxx | 123 ++++++++++++++-- common/rfb/benchmark.h | 289 ++++++++++++++++++++++++++++++++++--- 4 files changed, 394 insertions(+), 42 deletions(-) diff --git a/common/rfb/ServerCore.cxx b/common/rfb/ServerCore.cxx index 0921665..bc5a4bd 100644 --- a/common/rfb/ServerCore.cxx +++ b/common/rfb/ServerCore.cxx @@ -32,15 +32,15 @@ rfb::IntParameter rfb::Server::idleTimeout 0, 0); rfb::IntParameter rfb::Server::maxDisconnectionTime ("MaxDisconnectionTime", - "Terminate when no client has been connected for s seconds", + "Terminate when no client has been connected for s seconds", 0, 0); rfb::IntParameter rfb::Server::maxConnectionTime ("MaxConnectionTime", - "Terminate when a client has been connected for s seconds", + "Terminate when a client has been connected for s seconds", 0, 0); rfb::IntParameter rfb::Server::maxIdleTime ("MaxIdleTime", - "Terminate after s seconds of user inactivity", + "Terminate after s seconds of user inactivity", 0, 0); rfb::IntParameter rfb::Server::clientWaitTimeMillis ("ClientWaitTimeMillis", @@ -117,10 +117,10 @@ rfb::BoolParameter rfb::Server::selfBench ("SelfBench", "Run self-benchmarks and exit.", false); -rfb::StringParameter rfb::Server::benchmark ( +rfb::StringParameter rfb::Server::benchmark( "Benchmark", "Run extended benchmarks and exit.", - "video.mp4"); + ""); rfb::IntParameter rfb::Server::dynamicQualityMin ("DynamicQualityMin", "The minimum dynamic JPEG quality, 0 = low, 9 = high", @@ -275,16 +275,16 @@ rfb::IntParameter rfb::Server::udpFullFrameFrequency ("udpFullFrameFrequency", "Send a full frame every N frames for clients using UDP. 0 to disable", 0, 0, 1000); - + rfb::IntParameter rfb::Server::udpPort ("udpPort", "Which port to use for UDP. Default same as websocket", 0, 0, 65535); static void bandwidthPreset() { - rfb::Server::dynamicQualityMin.setParam(2); - rfb::Server::dynamicQualityMax.setParam(9); - rfb::Server::treatLossless.setParam(8); + rfb::Server::dynamicQualityMin.setParam(2); + rfb::Server::dynamicQualityMax.setParam(9); + rfb::Server::treatLossless.setParam(8); } rfb::PresetParameter rfb::Server::preferBandwidth diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index b1ef22f..ab6619c 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -129,7 +129,7 @@ static void parseRegionPart(const bool percents, rdr::U16 &pcdest, int &dest, *inptr = ptr; } -VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_, bool a) +VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) : blHosts(&blacklist), desktop(desktop_), desktopStarted(false), blockCounter(0), pb(nullptr), blackedpb(nullptr), ledState(ledUnknown), name(strDup(name_)), pointerClient(nullptr), clipboardClient(nullptr), @@ -232,9 +232,9 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_, bool a) if (Server::selfBench) SelfBench(); - if (Server::benchmark) { + if (Server::benchmark[0]) { auto *file_name = Server::benchmark.getValueStr(); - if (std::filesystem::exists(file_name)) + if (!std::filesystem::exists(file_name)) throw Exception("Benchmarking video file does not exist"); benchmark(file_name); } diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index d80c2ed..a7e0cbf 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -20,12 +20,14 @@ #include #include #include -#include "VNCServer.h" - -static rfb::LogWriter vlog("Benchmarking"); +#include +#include void benchmark(const std::string &path) { AVFormatContext *format_ctx = nullptr; + + vlog.info("Benchmarking with video file %s", path.c_str()); + if (avformat_open_input(&format_ctx, path.c_str(), nullptr, nullptr) < 0) throw std::runtime_error("Could not open video file"); @@ -53,7 +55,7 @@ void benchmark(const std::string &path) { if (!codec) throw std::runtime_error("Codec not found"); - CodecCtxGuard codex_ctx_guard{avcodec_alloc_context3(codec)}; + const CodecCtxGuard codex_ctx_guard{avcodec_alloc_context3(codec)}; auto *codec_ctx = codex_ctx_guard.get(); if (!codec_ctx || avcodec_parameters_to_context(codec_ctx, codec_parameters) < 0) @@ -63,10 +65,10 @@ void benchmark(const std::string &path) { throw std::runtime_error("Could not open codec"); // Allocate frame and packet - FrameGuard frame_guard{av_frame_alloc()}; + const FrameGuard frame_guard{av_frame_alloc()}; auto *frame = frame_guard.get(); - PacketGuard packet_guard{av_packet_alloc()}; + const PacketGuard packet_guard{av_packet_alloc()}; auto *packet = packet_guard.get(); if (!frame || !packet) @@ -84,7 +86,7 @@ void benchmark(const std::string &path) { SwsContextGuard sws_ctx_guard{sws_ctx}; - FrameGuard rgb_frame_guard{av_frame_alloc()}; + const FrameGuard rgb_frame_guard{av_frame_alloc()}; auto *rgb_frame = rgb_frame_guard.get(); if (!rgb_frame) @@ -95,15 +97,19 @@ void benchmark(const std::string &path) { rgb_frame->height = codec_ctx->height; static const rfb::PixelFormat pf{32, 24, false, true, 0xFF, 0xFF, 0xFF, 0, 8, 16}; - const rfb::Rect rect{0, 0, rgb_frame->width, rgb_frame->height}; - rfb::ManagedPixelBuffer pb{pf, rect.width(), rect.height()}; - - server->setPixelBuffer(&pb); + auto *pb = new rfb::ManagedPixelBuffer{pf, rgb_frame->width, rgb_frame->height}; + rfb::MockCConnection connection{pb}; if (av_frame_get_buffer(rgb_frame, 0) != 0) throw std::runtime_error("Could not allocate frame data"); + uint64_t frames{}; + const size_t total_frame_count = format_ctx->streams[video_stream_idx]->nb_frames; + + std::vector timings(total_frame_count > 0 ? total_frame_count : 2048, 0); + + vlog.info("Reading frames..."); while (av_read_frame(format_ctx, packet) == 0) { if (packet->stream_index == video_stream_idx) { if (avcodec_send_packet(codec_ctx, packet) == 0) { @@ -112,11 +118,104 @@ void benchmark(const std::string &path) { sws_scale(sws_ctx, frame->data, frame->linesize, 0, frame->height, rgb_frame->data, rgb_frame->linesize); + vlog.info("Updating with frame %lu", frames); + connection.framebufferUpdateStart(); + vlog.info("Setting frame"); + connection.setNewFrame(rgb_frame); + using namespace std::chrono; - pb.imageRect(rect, rgb_frame->data[0], rect.width()); + auto now = high_resolution_clock::now(); + vlog.info("Updating frame..."); + connection.framebufferUpdateEnd(); + const auto duration = duration_cast(high_resolution_clock::now() - now).count(); + + vlog.info("Frame took %lu ns", duration); + + auto [jpeg_stats, webp_stats, bytes, udp_bytes] = connection.getStats(); + vlog.info("JPEG stats: %d ms", jpeg_stats.ms); + vlog.info("JPEG stats: %d rects", jpeg_stats.rects); + + vlog.info("WebP stats: %d ms", webp_stats.ms); + vlog.info("WebP stats: %d rects", webp_stats.rects); + + + timings[frames++] = duration; } } } av_packet_unref(packet); } + vlog.info("Done reading frames..."); + + if (frames > 0) { + timings.reserve(frames + 1); + + const auto sum = std::accumulate(timings.begin(), timings.end(), 0.); + const auto size = timings.size(); + const auto average = sum / static_cast(size); + + double median{}; + + std::sort(timings.begin(), timings.end()); + if (size % 2 == 0) + median = static_cast(timings[size / 2]); + else + median = static_cast(timings[size / 2 - 1] + timings[size / 2]) / 2.; + + auto [jpeg_stats, webp_stats, bytes, udp_bytes] = connection.getStats(); + + vlog.info("Average time encoding frame: %f ns", average); + vlog.info("Median time encoding frame: %f ns", median); + vlog.info("Total time: %f ns", sum); + + tinyxml2::XMLDocument doc; + + auto *test_suit = doc.NewElement("testsuite"); + test_suit->SetAttribute("name", "Benchmark"); + + doc.InsertFirstChild(test_suit); + + auto *test_case = doc.NewElement("testcase"); + test_case->SetAttribute("name", "Average time encoding frame, ms"); + test_case->SetAttribute("time", average / 1000); + test_case->SetAttribute("runs", 1); + test_case->SetAttribute("classname", "KasmVNC"); + test_suit->InsertEndChild(test_case); + + test_case = doc.NewElement("testcase"); + test_case->SetAttribute("name", "Median time encoding frame, ms"); + test_case->SetAttribute("time", average / 1000); + test_case->SetAttribute("runs", 1); + test_case->SetAttribute("classname", "KasmVNC"); + test_suit->InsertEndChild(test_case); + + test_case = doc.NewElement("testcase"); + test_case->SetAttribute("name", "Total time encoding, ms"); + test_case->SetAttribute("time", sum); + test_case->SetAttribute("runs", 1); + test_case->SetAttribute("classname", "KasmVNC"); + test_suit->InsertEndChild(test_case); + + test_case = doc.NewElement("testcase"); + test_case->SetAttribute("name", "KBytes sent"); + test_case->SetAttribute("time", bytes / 1024); + test_case->SetAttribute("runs", 1); + test_case->SetAttribute("classname", "KasmVNC"); + test_suit->InsertEndChild(test_case); + + test_case = doc.NewElement("testcase"); + test_case->SetAttribute("name", "KBytes sent (UDP)"); + test_case->SetAttribute("time", udp_bytes / 1024); + test_case->SetAttribute("runs", 1); + test_case->SetAttribute("classname", "KasmVNC"); + test_suit->InsertEndChild(test_case); + + test_suit->SetAttribute("tests", 5); + test_suit->SetAttribute("failures", 0); + //test_suit->SetAttribute("time", total_time); + + doc.SaveFile("Benchmark.xml"); + } + + exit(0); } diff --git a/common/rfb/benchmark.h b/common/rfb/benchmark.h index 61edae5..375fd8c 100644 --- a/common/rfb/benchmark.h +++ b/common/rfb/benchmark.h @@ -18,16 +18,29 @@ #pragma once -#include "Timer.h" #include +#include #include +#include "CConnection.h" +#include "CMsgReader.h" +#include "EncCache.h" +#include "EncodeManager.h" +#include "LogWriter.h" +#include "SMsgWriter.h" + +namespace rdr { + class FileInStream; +} + extern "C" { #include #include #include } +static rfb::LogWriter vlog("Benchmarking"); + struct AVFormatContextDeleter { void operator()(AVFormatContext *ctx) const { avformat_close_input(&ctx); @@ -64,39 +77,279 @@ using FrameGuard = std::unique_ptr; using SwsContextGuard = std::unique_ptr; using PacketGuard = std::unique_ptr; + namespace rfb { - class BenchmarkServer : public VNCServer, public Timer::Callback { + class MockBufferStream : public rdr::BufferedInStream { + bool fillBuffer(size_t maxSize, bool wait) override { + return true; + } + }; + + class MockStream final : public rdr::OutStream { public: - bool handleTimeout(Timer *t) override; + MockStream() { + offset = 0; + ptr = buf; + end = buf + sizeof(buf); + } - void add_changed(const Region ®ion) override; + private: + void overrun(size_t needed) override { + flush(); - void add_copied(const Region &dest, const Point &delta) override; + /*if (itemSize * nItems > end - ptr) + nItems = (end - ptr) / itemSize; + return nItems;*/ + } - void blockUpdates() override; + public: + size_t length() override { + flush(); + return offset; + } - void unblockUpdates() override; + void flush() override { + offset += ptr - buf; + ptr = buf; + } - void setPixelBuffer(PixelBuffer *pb, const ScreenSet &layout) override; + private: + ptrdiff_t offset; + rdr::U8 buf[131072]{}; + }; - void setPixelBuffer(PixelBuffer *pb) override; + class MockSConnection : public SConnection { + public: + MockSConnection() { + setStreams(nullptr, &out); - void setScreenLayout(const ScreenSet &layout) override; + setWriter(new SMsgWriter(&cp, &out, &udps)); + } - [[nodiscard]] PixelBuffer *getPixelBuffer() const override; + ~MockSConnection() override = default; - void announceClipboard(bool available) override; + void writeUpdate(const UpdateInfo &ui, const rfb::PixelBuffer *pb) { + vlog.info("Writing update"); + // Drop any lossy tracking that is now outside the framebuffer + //manager.pruneLosslessRefresh(Region(pb->getRect())); - void bell() override; + bytes += out.length(); + udp_bytes += udps.length(); - void closeClients(const char *reason) override; + vlog.info("bytes written: %lu", bytes); + vlog.info("udp bytes written: %lu", udp_bytes); - void setCursor(int width, int height, const Point &hotspot, const rdr::U8 *cursorData, bool resizing) override; + cache.clear(); + manager.writeUpdate(ui, pb, nullptr); + } - void setCursorPos(const Point &p, bool warped) override; + virtual void setAccessRights(AccessRights ar) { + } - void setName(const char *name) override; + void setDesktopSize(int fb_width, int fb_height, + const rfb::ScreenSet &layout) override { + cp.width = fb_width; + cp.height = fb_height; + cp.screenLayout = layout; - void setLEDState(unsigned state) override; + writer()->writeExtendedDesktopSize(); + writer()->writeSetDesktopSize(); + } + + void sendStats(const bool toClient) override { + } + + [[nodiscard]] bool canChangeKasmSettings() const override { + return false; + } + + void udpUpgrade(const char *resp) override { + } + + void udpDowngrade(const bool) override { + } + + void subscribeUnixRelay(const char *name) override { + } + + void unixRelay(const char *name, const rdr::U8 *buf, const unsigned len) override { + } + + void handleFrameStats(rdr::U32 all, rdr::U32 render) override { + } + + [[nodiscard]] auto getJpegStats() const { + return manager.jpegstats; + } + + [[nodiscard]] auto getWebPStats() const { + return manager.webpstats; + } + + uint64_t bytes; + uint64_t udp_bytes; + + protected: + MockStream out{}; + MockStream udps{}; + + EncCache cache{}; + EncodeManager manager{this, &cache}; + }; + + static constexpr rdr::S32 encodings[] = { + pseudoEncodingWEBP, + pseudoEncodingJpegVideoQualityLevel0, + pseudoEncodingJpegVideoQualityLevel9, + pseudoEncodingWebpVideoQualityLevel0, + pseudoEncodingWebpVideoQualityLevel9, + pseudoEncodingTreatLosslessLevel0, + pseudoEncodingTreatLosslessLevel10, + pseudoEncodingPreferBandwidth, + pseudoEncodingDynamicQualityMinLevel0, + pseudoEncodingDynamicQualityMinLevel9, + pseudoEncodingDynamicQualityMaxLevel0, + pseudoEncodingDynamicQualityMaxLevel9, + pseudoEncodingVideoAreaLevel1, + pseudoEncodingVideoAreaLevel100, + pseudoEncodingVideoTimeLevel0, + pseudoEncodingVideoTimeLevel100, + + pseudoEncodingFrameRateLevel10, + pseudoEncodingFrameRateLevel60, + pseudoEncodingMaxVideoResolution, + pseudoEncodingVideoScalingLevel0, + pseudoEncodingVideoScalingLevel9, + pseudoEncodingVideoOutTimeLevel1, + pseudoEncodingVideoOutTimeLevel100, + pseudoEncodingQOI + }; + + class MockCConnection final : public CConnection { + public: + explicit MockCConnection(ManagedPixelBuffer *pb) { + setStreams(&in, nullptr); + + // Need to skip the initial handshake and ServerInit + setState(RFBSTATE_NORMAL); + // That also means that the reader and writer weren't setup + setReader(new rfb::CMsgReader(this, &in)); + auto &pf = pb->getPF(); + CMsgHandler::setPixelFormat(pf); + + MockCConnection::setDesktopSize(pb->width(), pb->height()); + setFramebuffer(pb); + + cp.setPF(pf); + + sc.cp.setPF(pf); + sc.setEncodings(std::size(encodings), encodings); + } + + void setCursor(int width, int height, const Point &hotspot, const rdr::U8 *data, const bool resizing) override { + } + + ~MockCConnection() override = default; + + + struct stats_t { + EncodeManager::codecstats_t jpeg_stats; + EncodeManager::codecstats_t webp_stats; + uint64_t bytes; + uint64_t udp_bytes; + }; + + [[nodiscard]] stats_t getStats() const { + return { + sc.getJpegStats(), + sc.getWebPStats(), + sc.bytes, + sc.udp_bytes + }; + } + + void setDesktopSize(int w, int h) override { + CConnection::setDesktopSize(w, h); + + if (screen_layout.num_screens()) + screen_layout.remove_screen(0); + + screen_layout.add_screen(Screen(0, 0, 0, w, h, 0)); + //cp.screenLayout = screen_layout; + //sc.setDesktopSize(w, h, screen_layout); + vlog.info("setDesktopSize"); + } + + void setNewFrame(const AVFrame *frame) { + auto *pb = getFramebuffer(); + const int width = pb->width(); + const int height = pb->height(); + const rfb::Rect rect(0, 0, width, height); + + int dstStride; + auto *buffer = pb->getBufferRW(rect, &dstStride); + + const PixelFormat &pf = pb->getPF(); + + // Source data and stride from FFmpeg + const auto *srcData = frame->data[0]; + const int srcStride = frame->linesize[0] / 3; // Convert bytes to pixels + + vlog.info("Frame stride %d", srcStride); + + // Convert from RGB format to the PixelBuffer's format + pf.bufferFromRGB(buffer, srcData, width, srcStride, height); + + // Commit changes + pb->commitBufferRW(rect); + } + + void framebufferUpdateStart() override { + CConnection::framebufferUpdateStart(); + + updates.clear(); + } + + void framebufferUpdateEnd() override { + const PixelBuffer *pb = getFramebuffer(); + + UpdateInfo ui; + + const Region clip(pb->getRect()); + + CConnection::framebufferUpdateEnd(); + + //updates.add_changed(pb->getRect()); + updates.getUpdateInfo(&ui, clip); + vlog.info("%d", ui.changed.numRects()); + vlog.info("%d", ui.copied.numRects()); + vlog.info("%lu", ui.copypassed.size()); + sc.writeUpdate(ui, pb); + } + + void dataRect(const Rect &r, int encoding) override { + CConnection::dataRect(r, encoding); + + if (encoding != encodingCopyRect) // FIXME + updates.add_changed(Region(r)); + } + + void setColourMapEntries(int, int, rdr::U16 *) override { + } + + void bell() override { + } + + void serverCutText(const char *, rdr::U32) override { + } + + void serverCutText(const char *str) override { + } + + protected: + MockBufferStream in; + ScreenSet screen_layout; + SimpleUpdateTracker updates; + MockSConnection sc; }; } From ba218f1a26074941d2418f16fc1ce76961ed7bdb Mon Sep 17 00:00:00 2001 From: El Date: Thu, 10 Apr 2025 14:13:51 +0500 Subject: [PATCH 131/167] KASM-6984 Update test job tags in .gitlab-ci.yml --- .gitlab-ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4017934..2a99d59 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -108,7 +108,7 @@ build_ubuntu_jammy: stage: build allow_failure: true tags: - - oci-fixed-amd + - kasmvnc-x86 before_script: - *prepare_build - *prepare_www @@ -536,6 +536,8 @@ test: - SelfBench.xml - Benchmark.xml script: + - bash wget https://kasmweb-build-artifacts.s3.us-east-1.amazonaws.com/kasmvnc/static/127072-737747495_small.mp4 + - bash ls -l - bash builder/test-vncserver From 666ffc210219a717db2c023c1d20ed50e1d7e81a Mon Sep 17 00:00:00 2001 From: El Date: Thu, 10 Apr 2025 15:06:30 +0500 Subject: [PATCH 132/167] KASM-6984 Add FFmpeg libraries to Ubuntu focal build dependencies. Added new dependencies: libavformat-dev and libswscale-dev --- builder/dockerfile.ubuntu_focal.deb.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/dockerfile.ubuntu_focal.deb.build b/builder/dockerfile.ubuntu_focal.deb.build index ffe6402..5528d2c 100644 --- a/builder/dockerfile.ubuntu_focal.deb.build +++ b/builder/dockerfile.ubuntu_focal.deb.build @@ -3,7 +3,7 @@ FROM ubuntu:focal ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs libtbb-dev + apt-get -y install vim build-essential devscripts equivs libtbb-dev libavformat-dev libswscale-dev # Install build-deps for the package. COPY ./debian/control /tmp From 360b75e8e65ee758e7d613510d1d763dd36ea7a9 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 14 Apr 2025 14:53:05 +0500 Subject: [PATCH 133/167] KASM-6984 Update file download path. Update CI --- .gitlab-ci.yml | 2 -- builder/dockerfile.ubuntu_focal.specs.test | 2 +- spec/vncserver_adv_benchmarking_spec.py | 14 ++++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 spec/vncserver_adv_benchmarking_spec.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2a99d59..8e7bb40 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -536,8 +536,6 @@ test: - SelfBench.xml - Benchmark.xml script: - - bash wget https://kasmweb-build-artifacts.s3.us-east-1.amazonaws.com/kasmvnc/static/127072-737747495_small.mp4 - - bash ls -l - bash builder/test-vncserver diff --git a/builder/dockerfile.ubuntu_focal.specs.test b/builder/dockerfile.ubuntu_focal.specs.test index 663fe3d..414aebc 100644 --- a/builder/dockerfile.ubuntu_focal.specs.test +++ b/builder/dockerfile.ubuntu_focal.specs.test @@ -6,7 +6,7 @@ RUN apt-get update && apt-get install -y vim less RUN apt-get update && apt-get install -y python3-pip RUN apt-get update && apt-get install -y strace silversearcher-ag xfonts-base RUN apt-get update && apt-get install -y cinnamon -RUN apt-get update && apt-get install -y mate +RUN apt-get update && apt-get install -y mate wget RUN useradd -m docker diff --git a/spec/vncserver_adv_benchmarking_spec.py b/spec/vncserver_adv_benchmarking_spec.py new file mode 100644 index 0000000..a67ae55 --- /dev/null +++ b/spec/vncserver_adv_benchmarking_spec.py @@ -0,0 +1,14 @@ +from mamba import description, context, it, fit, before, after +from expects import expect, equal, contain, match +from helper.spec_helper import run_cmd, clean_env, kill_xvnc, clean_locks + +with description("Benchmarking"): + with before.each: + clean_env() + with after.each: + kill_xvnc() + with it("runs benchmarks"): + run_cmd("wget --no-check-certificate https://kasmweb-build-artifacts.s3.us-east-1.amazonaws.com/kasmvnc/static/127072-737747495_small.mp4 -o /tmp/video.mp4") + completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -Benchmark /tmp/video.mp4") + clean_locks() + expect(completed_process.returncode).to(equal(0)) From 15de8da56be55b981257ec403ca0988b74d1febf Mon Sep 17 00:00:00 2001 From: El Date: Thu, 17 Apr 2025 14:36:46 +0500 Subject: [PATCH 134/167] KASM-6984 Add additional tools and scripts to Dockerfile for dev setup --- spec/helper/spec_helper.py | 1 + spec/vncserver_benchmarking_spec.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/helper/spec_helper.py b/spec/helper/spec_helper.py index 3079296..c31692e 100644 --- a/spec/helper/spec_helper.py +++ b/spec/helper/spec_helper.py @@ -104,3 +104,4 @@ def kill_xvnc(): run_cmd('vncserver -kill :1', print_stderr=False) running_xvnc = False + clean_locks() diff --git a/spec/vncserver_benchmarking_spec.py b/spec/vncserver_benchmarking_spec.py index 1cb59b1..a6bb26a 100644 --- a/spec/vncserver_benchmarking_spec.py +++ b/spec/vncserver_benchmarking_spec.py @@ -1,6 +1,6 @@ from mamba import description, context, it, fit, before, after from expects import expect, equal, contain, match -from helper.spec_helper import run_cmd, clean_env, kill_xvnc +from helper.spec_helper import run_cmd, clean_env, kill_xvnc, clean_locks with description("Benchmarking"): with before.each: @@ -9,4 +9,5 @@ with description("Benchmarking"): kill_xvnc() with it("runs benchmarks"): completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -selfBench") - expect(completed_process.returncode).to(equal(0)) + clean_locks() + expect(completed_process.returncode).to(equal(0)) \ No newline at end of file From 96f1cfb79a766e190ff968345ab39ca1dade2df0 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 17 Apr 2025 21:06:09 +0500 Subject: [PATCH 135/167] KASM-6984 script debugging --- spec/vncserver_adv_benchmarking_spec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/vncserver_adv_benchmarking_spec.py b/spec/vncserver_adv_benchmarking_spec.py index a67ae55..9f2bb6b 100644 --- a/spec/vncserver_adv_benchmarking_spec.py +++ b/spec/vncserver_adv_benchmarking_spec.py @@ -8,7 +8,7 @@ with description("Benchmarking"): with after.each: kill_xvnc() with it("runs benchmarks"): - run_cmd("wget --no-check-certificate https://kasmweb-build-artifacts.s3.us-east-1.amazonaws.com/kasmvnc/static/127072-737747495_small.mp4 -o /tmp/video.mp4") + run_cmd("wget --no-check-certificate https://kasmweb-build-artifacts.s3.us-east-1.amazonaws.com/kasmvnc/static/127072-737747495_small.mp4 -O /tmp/video.mp4") completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -Benchmark /tmp/video.mp4") clean_locks() expect(completed_process.returncode).to(equal(0)) From de506f00c39310a2a372f8c1bbd1c3542b3194cf Mon Sep 17 00:00:00 2001 From: El Date: Thu, 17 Apr 2025 21:42:12 +0500 Subject: [PATCH 136/167] KASM-6984 Remove redundant clean_locks calls from benchmarking tests --- spec/vncserver_adv_benchmarking_spec.py | 1 - spec/vncserver_benchmarking_spec.py | 1 - 2 files changed, 2 deletions(-) diff --git a/spec/vncserver_adv_benchmarking_spec.py b/spec/vncserver_adv_benchmarking_spec.py index 9f2bb6b..053eeb2 100644 --- a/spec/vncserver_adv_benchmarking_spec.py +++ b/spec/vncserver_adv_benchmarking_spec.py @@ -10,5 +10,4 @@ with description("Benchmarking"): with it("runs benchmarks"): run_cmd("wget --no-check-certificate https://kasmweb-build-artifacts.s3.us-east-1.amazonaws.com/kasmvnc/static/127072-737747495_small.mp4 -O /tmp/video.mp4") completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -Benchmark /tmp/video.mp4") - clean_locks() expect(completed_process.returncode).to(equal(0)) diff --git a/spec/vncserver_benchmarking_spec.py b/spec/vncserver_benchmarking_spec.py index a6bb26a..a78d1e1 100644 --- a/spec/vncserver_benchmarking_spec.py +++ b/spec/vncserver_benchmarking_spec.py @@ -9,5 +9,4 @@ with description("Benchmarking"): kill_xvnc() with it("runs benchmarks"): completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -selfBench") - clean_locks() expect(completed_process.returncode).to(equal(0)) \ No newline at end of file From ebce680e79de13c8aa7b5a4c1dc5c7458654b470 Mon Sep 17 00:00:00 2001 From: El Date: Fri, 18 Apr 2025 16:48:47 +0500 Subject: [PATCH 137/167] KASM-6984 Refactor benchmark test case generation logic --- common/rfb/benchmark.cxx | 63 ++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index a7e0cbf..c5d6f20 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -22,6 +22,7 @@ #include #include #include +#include void benchmark(const std::string &path) { AVFormatContext *format_ctx = nullptr; @@ -132,12 +133,11 @@ void benchmark(const std::string &path) { vlog.info("Frame took %lu ns", duration); auto [jpeg_stats, webp_stats, bytes, udp_bytes] = connection.getStats(); - vlog.info("JPEG stats: %d ms", jpeg_stats.ms); - vlog.info("JPEG stats: %d rects", jpeg_stats.rects); - - vlog.info("WebP stats: %d ms", webp_stats.ms); - vlog.info("WebP stats: %d rects", webp_stats.rects); + //vlog.info("JPEG stats: %d ms", jpeg_stats.ms); + //vlog.info("JPEG stats: %d rects", jpeg_stats.rects); + //vlog.info("WebP stats: %d ms", webp_stats.ms); + // vlog.info("WebP stats: %d rects", webp_stats.rects); timings[frames++] = duration; } @@ -175,44 +175,31 @@ void benchmark(const std::string &path) { doc.InsertFirstChild(test_suit); - auto *test_case = doc.NewElement("testcase"); - test_case->SetAttribute("name", "Average time encoding frame, ms"); - test_case->SetAttribute("time", average / 1000); - test_case->SetAttribute("runs", 1); - test_case->SetAttribute("classname", "KasmVNC"); - test_suit->InsertEndChild(test_case); + constexpr auto div = 1. / (1000 * 1000); + auto total_tests{0}; - test_case = doc.NewElement("testcase"); - test_case->SetAttribute("name", "Median time encoding frame, ms"); - test_case->SetAttribute("time", average / 1000); - test_case->SetAttribute("runs", 1); - test_case->SetAttribute("classname", "KasmVNC"); - test_suit->InsertEndChild(test_case); + auto add_benchmark_item = [&doc, &test_suit, &total_tests](const char *name, auto value) { + auto *test_case = doc.NewElement("testcase"); + test_case->SetAttribute("name", name); + test_case->SetAttribute("time", value); + test_case->SetAttribute("runs", 1); + test_case->SetAttribute("classname", "KasmVNC"); + test_suit->InsertEndChild(test_case); - test_case = doc.NewElement("testcase"); - test_case->SetAttribute("name", "Total time encoding, ms"); - test_case->SetAttribute("time", sum); - test_case->SetAttribute("runs", 1); - test_case->SetAttribute("classname", "KasmVNC"); - test_suit->InsertEndChild(test_case); + ++total_tests; + }; - test_case = doc.NewElement("testcase"); - test_case->SetAttribute("name", "KBytes sent"); - test_case->SetAttribute("time", bytes / 1024); - test_case->SetAttribute("runs", 1); - test_case->SetAttribute("classname", "KasmVNC"); - test_suit->InsertEndChild(test_case); + add_benchmark_item("Average time encoding frame, ms", average * div); + add_benchmark_item("Median time encoding frame, ms", median * div); + add_benchmark_item("Total time encoding, ms", sum * div); - test_case = doc.NewElement("testcase"); - test_case->SetAttribute("name", "KBytes sent (UDP)"); - test_case->SetAttribute("time", udp_bytes / 1024); - test_case->SetAttribute("runs", 1); - test_case->SetAttribute("classname", "KasmVNC"); - test_suit->InsertEndChild(test_case); + std::stringstream ss; + ss << "KBytes sent: " << bytes / 1024; + add_benchmark_item(ss.str().c_str(), 0); - test_suit->SetAttribute("tests", 5); - test_suit->SetAttribute("failures", 0); - //test_suit->SetAttribute("time", total_time); + //ss.flush(); + //ss << "KBytes sent (UDP): " << udp_bytes / 1024; + //add_benchmark_item(ss.str().c_str(), 0); doc.SaveFile("Benchmark.xml"); } From 1a2fb0341de3928e37594649755f280a2830a1e8 Mon Sep 17 00:00:00 2001 From: El Date: Sat, 19 Apr 2025 01:30:59 +0500 Subject: [PATCH 138/167] KASM-6984 Add FFmpeg support and update dependencies for benchmarking on oracle 9 --- builder/dockerfile.oracle_9.build | 1 + common/rfb/CMakeLists.txt | 1 + common/rfb/benchmark.cxx | 1 + 3 files changed, 3 insertions(+) diff --git a/builder/dockerfile.oracle_9.build b/builder/dockerfile.oracle_9.build index aaa9184..674e2f0 100644 --- a/builder/dockerfile.oracle_9.build +++ b/builder/dockerfile.oracle_9.build @@ -43,6 +43,7 @@ RUN dnf install -y --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion- # Install from new repos RUN dnf install -y \ giflib-devel \ + ffmpeg-devel \ lbzip2 \ libXfont2-devel \ libxkbfile-devel \ diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt index a99e548..1094ece 100644 --- a/common/rfb/CMakeLists.txt +++ b/common/rfb/CMakeLists.txt @@ -141,6 +141,7 @@ target_include_directories(rfb PRIVATE ${PNG_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/unix/kasmvncpasswd ${CMAKE_SOURCE_DIR}/third_party/tinyxml2 + ${FFMPEG_INCLUDE_DIRS} ) target_link_libraries(rfb PRIVATE ${RFB_LIBRARIES} tinyxml2_objs ${FFMPEG_LIBRARIES}) diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index c5d6f20..907a740 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include void benchmark(const std::string &path) { From 241592b19073798331bef5fd5f2e6c4c5c497445 Mon Sep 17 00:00:00 2001 From: El Date: Sat, 19 Apr 2025 02:55:36 +0500 Subject: [PATCH 139/167] KASM-6984 Add ffmpeg-dev to Alpine build Dockerfiles --- builder/dockerfile.alpine_318.build | 3 ++- builder/dockerfile.alpine_319.build | 3 ++- builder/dockerfile.alpine_320.build | 3 ++- builder/dockerfile.alpine_321.build | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/builder/dockerfile.alpine_318.build b/builder/dockerfile.alpine_318.build index b163664..f8620ba 100644 --- a/builder/dockerfile.alpine_318.build +++ b/builder/dockerfile.alpine_318.build @@ -67,7 +67,8 @@ RUN \ xorgproto \ xorg-server-common \ xorg-server-dev \ - xtrans + xtrans \ + ffmpeg-dev ENV SCRIPTS_DIR=/tmp/scripts diff --git a/builder/dockerfile.alpine_319.build b/builder/dockerfile.alpine_319.build index c0b18b7..d003855 100644 --- a/builder/dockerfile.alpine_319.build +++ b/builder/dockerfile.alpine_319.build @@ -67,7 +67,8 @@ RUN \ xorgproto \ xorg-server-common \ xorg-server-dev \ - xtrans + xtrans \ + ffmpeg-dev ENV SCRIPTS_DIR=/tmp/scripts diff --git a/builder/dockerfile.alpine_320.build b/builder/dockerfile.alpine_320.build index 8212b60..b282e6d 100644 --- a/builder/dockerfile.alpine_320.build +++ b/builder/dockerfile.alpine_320.build @@ -67,7 +67,8 @@ RUN \ xorgproto \ xorg-server-common \ xorg-server-dev \ - xtrans + xtrans \ + ffmpeg-dev ENV SCRIPTS_DIR=/tmp/scripts diff --git a/builder/dockerfile.alpine_321.build b/builder/dockerfile.alpine_321.build index 5ccb9ac..47a2cc7 100644 --- a/builder/dockerfile.alpine_321.build +++ b/builder/dockerfile.alpine_321.build @@ -67,7 +67,8 @@ RUN \ xorgproto \ xorg-server-common \ xorg-server-dev \ - xtrans + xtrans \ + ffmpeg-dev ENV SCRIPTS_DIR=/tmp/scripts From b1e5f709f721324d2a46581c5d289879c1a46e40 Mon Sep 17 00:00:00 2001 From: El Date: Sun, 20 Apr 2025 03:03:58 +0500 Subject: [PATCH 140/167] KASM-6984 Update dependencies in Dockerfile for Debian --- builder/dockerfile.debian_bookworm.build | 3 ++- builder/dockerfile.debian_bullseye.build | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/builder/dockerfile.debian_bookworm.build b/builder/dockerfile.debian_bookworm.build index c0c9212..98034c6 100644 --- a/builder/dockerfile.debian_bookworm.build +++ b/builder/dockerfile.debian_bookworm.build @@ -23,7 +23,8 @@ RUN apt-get update && \ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev RUN apt-get update && apt-get -y install ninja-build cmake nasm git libgnutls28-dev vim wget tightvncserver curl -RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev +RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev \ + libxcursor-dev libavformat-dev libswscale-dev ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR diff --git a/builder/dockerfile.debian_bullseye.build b/builder/dockerfile.debian_bullseye.build index 528b179..d9ce288 100644 --- a/builder/dockerfile.debian_bullseye.build +++ b/builder/dockerfile.debian_bullseye.build @@ -13,7 +13,8 @@ RUN apt-get update && \ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev RUN apt-get update && apt-get -y install ninja-build nasm git libgnutls28-dev vim wget tightvncserver curl -RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev +RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev \ + libxcursor-dev libavformat-dev libswscale-dev RUN CMAKE_URL="https://cmake.org/files/v3.22/cmake-3.22.0" && \ ARCH=$(arch) && \ From 7b0baed7d17e7fd332d5bc06a3de6ad1952d347d Mon Sep 17 00:00:00 2001 From: El Date: Sun, 20 Apr 2025 13:24:32 +0500 Subject: [PATCH 141/167] KASM-6984 Add libavformat-free-devel and libswscale-free-devel dependencies --- builder/dockerfile.fedora_forty.build | 4 +++- builder/dockerfile.fedora_fortyone.build | 4 +++- builder/dockerfile.fedora_thirtynine.build | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/builder/dockerfile.fedora_forty.build b/builder/dockerfile.fedora_forty.build index 686feb6..983a88f 100644 --- a/builder/dockerfile.fedora_forty.build +++ b/builder/dockerfile.fedora_forty.build @@ -72,7 +72,9 @@ RUN \ xorg-x11-server-common \ xorg-x11-server-devel \ xorg-x11-xtrans-devel \ - xsltproc + xsltproc \ + libavformat-free-devel \ + libswscale-free-devel ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR diff --git a/builder/dockerfile.fedora_fortyone.build b/builder/dockerfile.fedora_fortyone.build index 81c44b4..336b064 100644 --- a/builder/dockerfile.fedora_fortyone.build +++ b/builder/dockerfile.fedora_fortyone.build @@ -73,7 +73,9 @@ RUN \ xorg-x11-server-common \ xorg-x11-server-devel \ xorg-x11-xtrans-devel \ - xsltproc + xsltproc \ + libavformat-free-devel \ + libswscale-free-devel ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR diff --git a/builder/dockerfile.fedora_thirtynine.build b/builder/dockerfile.fedora_thirtynine.build index aa10cf4..d1985de 100644 --- a/builder/dockerfile.fedora_thirtynine.build +++ b/builder/dockerfile.fedora_thirtynine.build @@ -72,7 +72,9 @@ RUN \ xorg-x11-server-common \ xorg-x11-server-devel \ xorg-x11-xtrans-devel \ - xsltproc + xsltproc \ + libavformat-free-devel \ + libswscale-free-devel ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR From fd96e8ab9ce386a04e14691fe5fa4c993ee2be2b Mon Sep 17 00:00:00 2001 From: El Date: Sun, 20 Apr 2025 14:17:27 +0500 Subject: [PATCH 142/167] KASM-6984 Add depedencies to docker images --- builder/dockerfile.debian_bookworm.deb.build | 2 +- builder/dockerfile.debian_bullseye.deb.build | 2 +- builder/dockerfile.kali_kali-rolling.build | 3 ++- builder/dockerfile.opensuse_15.build | 4 +++- builder/dockerfile.ubuntu_focal.build | 4 ++-- builder/dockerfile.ubuntu_jammy.build | 3 ++- builder/dockerfile.ubuntu_jammy.deb.build | 2 +- builder/dockerfile.ubuntu_noble.build | 3 ++- builder/dockerfile.ubuntu_noble.deb.build | 2 +- 9 files changed, 15 insertions(+), 10 deletions(-) diff --git a/builder/dockerfile.debian_bookworm.deb.build b/builder/dockerfile.debian_bookworm.deb.build index 2e61fbb..7e38d57 100644 --- a/builder/dockerfile.debian_bookworm.deb.build +++ b/builder/dockerfile.debian_bookworm.deb.build @@ -3,7 +3,7 @@ FROM debian:bookworm ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs + apt-get -y install vim build-essential devscripts equivs libavformat-dev libswscale-dev # Install build-deps for the package. COPY ./debian/control /tmp diff --git a/builder/dockerfile.debian_bullseye.deb.build b/builder/dockerfile.debian_bullseye.deb.build index 51bde4f..e8c0ae1 100644 --- a/builder/dockerfile.debian_bullseye.deb.build +++ b/builder/dockerfile.debian_bullseye.deb.build @@ -3,7 +3,7 @@ FROM debian:bullseye ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs + apt-get -y install vim build-essential devscripts equivs libavformat-dev libswscale-dev # Install build-deps for the package. COPY ./debian/control /tmp diff --git a/builder/dockerfile.kali_kali-rolling.build b/builder/dockerfile.kali_kali-rolling.build index 43a1e3a..717e8f9 100644 --- a/builder/dockerfile.kali_kali-rolling.build +++ b/builder/dockerfile.kali_kali-rolling.build @@ -14,7 +14,8 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tz RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev RUN apt-get update && apt-get -y install gcc g++ curl RUN apt-get update && apt-get -y install ninja-build cmake nasm git libgnutls28-dev vim wget tightvncserver -RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev +RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev \ + libxcursor-dev libavformat-dev libswscale-dev ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR diff --git a/builder/dockerfile.opensuse_15.build b/builder/dockerfile.opensuse_15.build index 6c2cd1b..a385424 100644 --- a/builder/dockerfile.opensuse_15.build +++ b/builder/dockerfile.opensuse_15.build @@ -13,6 +13,8 @@ RUN zypper install -ny \ nasm \ curl \ ffmpeg-4-libavcodec-devel \ + ffmpeg-4-libswscale-devel \ + ffmpeg-4-libavformat-devel \ fonttosfnt \ font-util \ gcc14 \ @@ -46,12 +48,12 @@ RUN zypper install -ny \ xorg-x11-server-sdk \ xorg-x11-util-devel \ zlib-devel +#RUN zypper install -ny libavformat-devel libswscale-devel RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 140 \ --slave /usr/bin/g++ g++ /usr/bin/g++-14 \ --slave /usr/bin/gcov gcov /usr/bin/gcov-14 - RUN useradd -u 1000 docker && \ groupadd -g 1000 docker && \ usermod -a -G docker docker diff --git a/builder/dockerfile.ubuntu_focal.build b/builder/dockerfile.ubuntu_focal.build index 57c7373..a70c56a 100644 --- a/builder/dockerfile.ubuntu_focal.build +++ b/builder/dockerfile.ubuntu_focal.build @@ -39,5 +39,5 @@ RUN $SCRIPTS_DIR/build-libjpeg-turbo COPY --chown=docker:docker . /src/ -USER docker -ENTRYPOINT ["/src/builder/build.sh"] +#USER docker +#ENTRYPOINT ["/src/builder/build.sh"] diff --git a/builder/dockerfile.ubuntu_jammy.build b/builder/dockerfile.ubuntu_jammy.build index cc6c4ff..11eafc7 100644 --- a/builder/dockerfile.ubuntu_jammy.build +++ b/builder/dockerfile.ubuntu_jammy.build @@ -13,7 +13,8 @@ RUN apt-get update && \ RUN apt-get update && apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev RUN apt-get update && apt-get -y install ninja-build cmake nasm git libgnutls28-dev vim wget tightvncserver curl -RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev +RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev \ + libxcursor-dev libavformat-dev libswscale-dev ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR diff --git a/builder/dockerfile.ubuntu_jammy.deb.build b/builder/dockerfile.ubuntu_jammy.deb.build index 31dee99..ce9d84c 100644 --- a/builder/dockerfile.ubuntu_jammy.deb.build +++ b/builder/dockerfile.ubuntu_jammy.deb.build @@ -3,7 +3,7 @@ FROM ubuntu:jammy ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs + apt-get -y install vim build-essential devscripts equivs libavformat-dev libswscale-dev # Install build-deps for the package. COPY ./debian/control /tmp diff --git a/builder/dockerfile.ubuntu_noble.build b/builder/dockerfile.ubuntu_noble.build index a4c3a6f..dfb796c 100644 --- a/builder/dockerfile.ubuntu_noble.build +++ b/builder/dockerfile.ubuntu_noble.build @@ -13,7 +13,8 @@ RUN apt-get update && \ RUN apt-get update && apt-get install -y --no-install-recommends tzdata RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev RUN apt-get update && apt-get -y install ninja-build cmake nasm git libgnutls28-dev vim wget curl -RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev +RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev \ + libxcursor-dev libavformat-dev libswscale-dev ENV SCRIPTS_DIR=/tmp/scripts COPY builder/scripts $SCRIPTS_DIR diff --git a/builder/dockerfile.ubuntu_noble.deb.build b/builder/dockerfile.ubuntu_noble.deb.build index 6a56b24..982de54 100644 --- a/builder/dockerfile.ubuntu_noble.deb.build +++ b/builder/dockerfile.ubuntu_noble.deb.build @@ -3,7 +3,7 @@ FROM ubuntu:noble ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs + apt-get -y install vim build-essential devscripts equivs libavformat-dev libswscale-dev # Install build-deps for the package. COPY ./debian/control /tmp From f95c46f02de1bdd2e9412b520898f22f2f868554 Mon Sep 17 00:00:00 2001 From: El Date: Sun, 20 Apr 2025 14:33:31 +0500 Subject: [PATCH 143/167] KASM-6984 Set C++ standard to C++20 in CMake configuration --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ba357c..0ef404d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -UNDEBUG") # Make sure we get a sane C version set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") +set(CMAKE_CXX_STANDARD 20) # Enable OpenMP set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp") From 2859e86a7094b7c88517b44d115d8ec6aa65f35a Mon Sep 17 00:00:00 2001 From: El Date: Mon, 21 Apr 2025 14:47:46 +0500 Subject: [PATCH 144/167] KASM-6984 Added dependencies --- .gitlab-ci.yml | 2 +- builder/dockerfile.kali_kali-rolling.deb.build | 2 +- builder/dockerfile.ubuntu_focal.build | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8e7bb40..4017934 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -108,7 +108,7 @@ build_ubuntu_jammy: stage: build allow_failure: true tags: - - kasmvnc-x86 + - oci-fixed-amd before_script: - *prepare_build - *prepare_www diff --git a/builder/dockerfile.kali_kali-rolling.deb.build b/builder/dockerfile.kali_kali-rolling.deb.build index 6d0ed1b..3683530 100644 --- a/builder/dockerfile.kali_kali-rolling.deb.build +++ b/builder/dockerfile.kali_kali-rolling.deb.build @@ -3,7 +3,7 @@ FROM kalilinux/kali-rolling:latest ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs + apt-get -y install vim build-essential devscripts equivs libavformat-dev libswscale-dev # Install build-deps for the package. COPY ./debian/control /tmp diff --git a/builder/dockerfile.ubuntu_focal.build b/builder/dockerfile.ubuntu_focal.build index a70c56a..57c7373 100644 --- a/builder/dockerfile.ubuntu_focal.build +++ b/builder/dockerfile.ubuntu_focal.build @@ -39,5 +39,5 @@ RUN $SCRIPTS_DIR/build-libjpeg-turbo COPY --chown=docker:docker . /src/ -#USER docker -#ENTRYPOINT ["/src/builder/build.sh"] +USER docker +ENTRYPOINT ["/src/builder/build.sh"] From 20d70675393ba6211c9864b656860fbda430e4f7 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 21 Apr 2025 15:21:49 +0500 Subject: [PATCH 145/167] KASM-6984 Added dependencies --- builder/dockerfile.alpine_321.apk.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/dockerfile.alpine_321.apk.build b/builder/dockerfile.alpine_321.apk.build index 2bc1af0..6f41bde 100644 --- a/builder/dockerfile.alpine_321.apk.build +++ b/builder/dockerfile.alpine_321.apk.build @@ -1,7 +1,7 @@ FROM alpine:3.21 RUN apk add shadow bash -RUN apk add abuild sudo less +RUN apk add abuild sudo less ffmpeg-dev ENV HOME /src/alpine WORKDIR $HOME/kasmvncserver From 544295505ef6e099d3d71b7136ab0b0bc72fa5e2 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 21 Apr 2025 16:40:48 +0500 Subject: [PATCH 146/167] KASM-6984 Refactor benchmark code to simplify and modernize usage --- common/rfb/benchmark.cxx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index 907a740..a7f8c99 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -23,7 +23,6 @@ #include #include #include -#include void benchmark(const std::string &path) { AVFormatContext *format_ctx = nullptr; @@ -133,7 +132,7 @@ void benchmark(const std::string &path) { vlog.info("Frame took %lu ns", duration); - auto [jpeg_stats, webp_stats, bytes, udp_bytes] = connection.getStats(); + // auto [jpeg_stats, webp_stats, bytes, udp_bytes] = connection.getStats(); //vlog.info("JPEG stats: %d ms", jpeg_stats.ms); //vlog.info("JPEG stats: %d rects", jpeg_stats.rects); @@ -157,7 +156,7 @@ void benchmark(const std::string &path) { double median{}; - std::sort(timings.begin(), timings.end()); + std::ranges::sort(timings); if (size % 2 == 0) median = static_cast(timings[size / 2]); else @@ -176,13 +175,13 @@ void benchmark(const std::string &path) { doc.InsertFirstChild(test_suit); - constexpr auto div = 1. / (1000 * 1000); + constexpr auto div = 1. / (1000); auto total_tests{0}; auto add_benchmark_item = [&doc, &test_suit, &total_tests](const char *name, auto value) { auto *test_case = doc.NewElement("testcase"); test_case->SetAttribute("name", name); - test_case->SetAttribute("time", value); + test_case->SetAttribute("filename", value); test_case->SetAttribute("runs", 1); test_case->SetAttribute("classname", "KasmVNC"); test_suit->InsertEndChild(test_case); @@ -194,9 +193,7 @@ void benchmark(const std::string &path) { add_benchmark_item("Median time encoding frame, ms", median * div); add_benchmark_item("Total time encoding, ms", sum * div); - std::stringstream ss; - ss << "KBytes sent: " << bytes / 1024; - add_benchmark_item(ss.str().c_str(), 0); + add_benchmark_item("Data sent, KBs", bytes / 1024); //ss.flush(); //ss << "KBytes sent (UDP): " << udp_bytes / 1024; From b325028d923305eaaa600a11c3122754cdc16dc3 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 21 Apr 2025 16:49:10 +0500 Subject: [PATCH 147/167] KASM-6984 Refactor benchmark code to simplify and modernize usage --- common/rfb/benchmark.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index a7f8c99..2117918 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -156,7 +156,7 @@ void benchmark(const std::string &path) { double median{}; - std::ranges::sort(timings); + std::sort(timings.begin(), timings.end()); if (size % 2 == 0) median = static_cast(timings[size / 2]); else From 9e79d8ae56b039ca098125448b19f383ba96af9c Mon Sep 17 00:00:00 2001 From: El Date: Mon, 21 Apr 2025 17:17:06 +0500 Subject: [PATCH 148/167] KASM-6984 Update copyright information in benchmark files --- common/rfb/benchmark.cxx | 4 ++-- common/rfb/benchmark.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index 2117918..8f8946e 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -1,5 +1,5 @@ -/* Copyright (C) 2025 Kasm Web -* +/* Copyright (C) 2025 Kasm Technologies Corp + * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or diff --git a/common/rfb/benchmark.h b/common/rfb/benchmark.h index 375fd8c..2cc21ce 100644 --- a/common/rfb/benchmark.h +++ b/common/rfb/benchmark.h @@ -1,5 +1,5 @@ -/* Copyright (C) 2025 Kasm Web -* +/* Copyright (C) 2025 Kasm Technologies Corp + * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or From fdc2f29ce2116c25bc6fa654c627fb985318342d Mon Sep 17 00:00:00 2001 From: El Date: Mon, 21 Apr 2025 22:14:42 +0500 Subject: [PATCH 149/167] KASM-6984 Update benchmarking --- common/rfb/benchmark.cxx | 14 +++++++++++++- spec/vncserver_adv_benchmarking_spec.py | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index 8f8946e..f4ec3dd 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -181,9 +181,21 @@ void benchmark(const std::string &path) { auto add_benchmark_item = [&doc, &test_suit, &total_tests](const char *name, auto value) { auto *test_case = doc.NewElement("testcase"); test_case->SetAttribute("name", name); - test_case->SetAttribute("filename", value); + test_case->SetAttribute("file", value); test_case->SetAttribute("runs", 1); test_case->SetAttribute("classname", "KasmVNC"); + + auto *props = doc.NewElement("properties"); + + auto *prop = doc.NewElement("property"); + prop->SetAttribute("name", name); + props->InsertEndChild(prop); + + prop = doc.NewElement("property"); + prop->SetAttribute("value", value); + props->InsertEndChild(prop); + + test_case->InsertEndChild(props); test_suit->InsertEndChild(test_case); ++total_tests; diff --git a/spec/vncserver_adv_benchmarking_spec.py b/spec/vncserver_adv_benchmarking_spec.py index 053eeb2..2b805ca 100644 --- a/spec/vncserver_adv_benchmarking_spec.py +++ b/spec/vncserver_adv_benchmarking_spec.py @@ -1,6 +1,6 @@ from mamba import description, context, it, fit, before, after from expects import expect, equal, contain, match -from helper.spec_helper import run_cmd, clean_env, kill_xvnc, clean_locks +from helper.spec_helper import run_cmd, clean_env, kill_xvnc with description("Benchmarking"): with before.each: @@ -10,4 +10,6 @@ with description("Benchmarking"): with it("runs benchmarks"): run_cmd("wget --no-check-certificate https://kasmweb-build-artifacts.s3.us-east-1.amazonaws.com/kasmvnc/static/127072-737747495_small.mp4 -O /tmp/video.mp4") completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -Benchmark /tmp/video.mp4") + command = '''sed -i "s/KasmVNC/$(grep -E '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"') $(grep -E '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2 | tr -d '"')/g" Benchmark.xml''' + run_cmd(command) expect(completed_process.returncode).to(equal(0)) From 4e3b8ac6c0a66080c9c1031f08c365042a9fc9bb Mon Sep 17 00:00:00 2001 From: El Date: Wed, 23 Apr 2025 00:28:14 +0500 Subject: [PATCH 150/167] KASM-6984 Add Docker Hub login step to CI pipeline --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4017934..ad6e84f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,6 +29,7 @@ stages: - pwd - apk add bash - mkdir -p "$GITLAB_SHARED_DIND_DIR" && chmod 777 "$GITLAB_SHARED_DIND_DIR" + - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD .prepare_www: &prepare_www - tar -zxf output/www/kasm_www.tar.gz -C builder/ From eff36f0a9571613eee1094a92ff4ebda622b9cc8 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 24 Apr 2025 06:27:02 +0500 Subject: [PATCH 151/167] KASM-6984 Remove unnecessary benchmark.h from RFB_SOURCES list --- common/rfb/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt index 1094ece..317fe2b 100644 --- a/common/rfb/CMakeLists.txt +++ b/common/rfb/CMakeLists.txt @@ -125,7 +125,6 @@ else () set(RFB_SOURCES ${RFB_SOURCES} ${SCALE_DUMMY_SOURCES} - benchmark.h ) endif () From 75dc2de7f8d633814c933dba0e11c20ceeb2b7f7 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 24 Apr 2025 06:33:28 +0500 Subject: [PATCH 152/167] KASM-6984 Refactor SConnection::setEncodings for readability and consistency --- common/rfb/SConnection.cxx | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx index f0e6be5..4546742 100644 --- a/common/rfb/SConnection.cxx +++ b/common/rfb/SConnection.cxx @@ -20,8 +20,6 @@ #include #include #include -#include -#include #include #include #include @@ -274,19 +272,16 @@ void SConnection::writeConnFailedFromScratch(const char* msg, os->flush(); } -void SConnection::setEncodings(int nEncodings, const rdr::S32* encodings) -{ - int i; - - preferredEncoding = encodingRaw; - for (i = 0;i < nEncodings;i++) { - if (EncodeManager::supported(encodings[i])) { - preferredEncoding = encodings[i]; - break; +void SConnection::setEncodings(int nEncodings, const rdr::S32 *encodings) { + preferredEncoding = encodingRaw; + for (int i = 0; i < nEncodings; i++) { + if (EncodeManager::supported(encodings[i])) { + preferredEncoding = encodings[i]; + break; + } } - } - SMsgHandler::setEncodings(nEncodings, encodings); + SMsgHandler::setEncodings(nEncodings, encodings); } void SConnection::clearBinaryClipboard() From 8180eb8b8758f742abcd71b355ded84f000af201 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 24 Apr 2025 07:12:28 +0500 Subject: [PATCH 153/167] KASM-6984 Refactor benchmarking --- common/rfb/benchmark.cxx | 14 ++-- common/rfb/benchmark.h | 134 ++++++++++++++++++++++----------------- 2 files changed, 83 insertions(+), 65 deletions(-) diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index f4ec3dd..1e7c9ae 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -119,18 +119,15 @@ void benchmark(const std::string &path) { sws_scale(sws_ctx, frame->data, frame->linesize, 0, frame->height, rgb_frame->data, rgb_frame->linesize); - vlog.info("Updating with frame %lu", frames); connection.framebufferUpdateStart(); - vlog.info("Setting frame"); connection.setNewFrame(rgb_frame); using namespace std::chrono; auto now = high_resolution_clock::now(); - vlog.info("Updating frame..."); connection.framebufferUpdateEnd(); - const auto duration = duration_cast(high_resolution_clock::now() - now).count(); + const auto duration = duration_cast(high_resolution_clock::now() - now).count(); - vlog.info("Frame took %lu ns", duration); + vlog.info("Frame took %lu ms", duration); // auto [jpeg_stats, webp_stats, bytes, udp_bytes] = connection.getStats(); //vlog.info("JPEG stats: %d ms", jpeg_stats.ms); @@ -166,7 +163,12 @@ void benchmark(const std::string &path) { vlog.info("Average time encoding frame: %f ns", average); vlog.info("Median time encoding frame: %f ns", median); - vlog.info("Total time: %f ns", sum); + vlog.info("Total time: %f ms", sum); + vlog.info("JPEG stats: %d ms", jpeg_stats.ms); + vlog.info("JPEG stats: %d rects", jpeg_stats.rects); + vlog.info("WebP stats: %d ms", webp_stats.ms); + vlog.info("WebP stats: %d rects", webp_stats.rects); + vlog.info("Total bytes sent: %lu bytes", bytes); tinyxml2::XMLDocument doc; diff --git a/common/rfb/benchmark.h b/common/rfb/benchmark.h index 2cc21ce..72a3914 100644 --- a/common/rfb/benchmark.h +++ b/common/rfb/benchmark.h @@ -18,6 +18,7 @@ #pragma once +#include #include #include #include @@ -27,6 +28,7 @@ #include "EncCache.h" #include "EncodeManager.h" #include "LogWriter.h" +#include "screenTypes.h" #include "SMsgWriter.h" namespace rdr { @@ -95,11 +97,9 @@ namespace rfb { private: void overrun(size_t needed) override { - flush(); - - /*if (itemSize * nItems > end - ptr) - nItems = (end - ptr) / itemSize; - return nItems;*/ + assert(end >= ptr); + if (needed > static_cast(end - ptr)) + flush(); } public: @@ -115,10 +115,10 @@ namespace rfb { private: ptrdiff_t offset; - rdr::U8 buf[131072]{}; + rdr::U8 buf[8192]{}; }; - class MockSConnection : public SConnection { + class MockSConnection final : public SConnection { public: MockSConnection() { setStreams(nullptr, &out); @@ -128,32 +128,70 @@ namespace rfb { ~MockSConnection() override = default; - void writeUpdate(const UpdateInfo &ui, const rfb::PixelBuffer *pb) { - vlog.info("Writing update"); - // Drop any lossy tracking that is now outside the framebuffer + void writeUpdate(const UpdateInfo &ui, const PixelBuffer *pb) { //manager.pruneLosslessRefresh(Region(pb->getRect())); bytes += out.length(); udp_bytes += udps.length(); - vlog.info("bytes written: %lu", bytes); - vlog.info("udp bytes written: %lu", udp_bytes); - cache.clear(); - manager.writeUpdate(ui, pb, nullptr); + + manager.clearEncodingTime(); + if (!ui.is_empty()) { + manager.writeUpdate(ui, pb, nullptr); + } else { + Region region{pb->getRect()}; + manager.writeLosslessRefresh(region, pb, nullptr, 2000); + } } - virtual void setAccessRights(AccessRights ar) { + void writeNoDataUpdate() { + if (!writer()->needNoDataUpdate()) + return; + + writer()->writeNoDataUpdate(); + } + + void WriteDataUpdate() { + Region req, pending; + + if (req.is_empty()) + return; + + if (!pending.is_empty()) { + UpdateInfo ui; + // However, we might still be able to send a lossless refresh + req.assign_subtract(pending); + req.assign_subtract(ui.changed); + req.assign_subtract(ui.copied); + + ui.changed.clear(); + ui.copied.clear(); + } + } + + void writeFramebufferUpdate() { + manager.clearEncodingTime(); + + if (state() != RFBSTATE_NORMAL) + return; + + // First, take care of any updates that cannot contain framebuffer data + // changes. + writeNoDataUpdate(); + + // Then real data (if possible) + WriteDataUpdate(); } void setDesktopSize(int fb_width, int fb_height, - const rfb::ScreenSet &layout) override { + const ScreenSet &layout) override { cp.width = fb_width; cp.height = fb_height; cp.screenLayout = layout; - writer()->writeExtendedDesktopSize(); - writer()->writeSetDesktopSize(); + writer()->writeExtendedDesktopSize(reasonServer, 0, cp.width, cp.height, + cp.screenLayout); } void sendStats(const bool toClient) override { @@ -186,8 +224,8 @@ namespace rfb { return manager.webpstats; } - uint64_t bytes; - uint64_t udp_bytes; + uint64_t bytes{}; + uint64_t udp_bytes{}; protected: MockStream out{}; @@ -198,31 +236,17 @@ namespace rfb { }; static constexpr rdr::S32 encodings[] = { - pseudoEncodingWEBP, - pseudoEncodingJpegVideoQualityLevel0, - pseudoEncodingJpegVideoQualityLevel9, - pseudoEncodingWebpVideoQualityLevel0, - pseudoEncodingWebpVideoQualityLevel9, - pseudoEncodingTreatLosslessLevel0, - pseudoEncodingTreatLosslessLevel10, - pseudoEncodingPreferBandwidth, - pseudoEncodingDynamicQualityMinLevel0, - pseudoEncodingDynamicQualityMinLevel9, - pseudoEncodingDynamicQualityMaxLevel0, - pseudoEncodingDynamicQualityMaxLevel9, - pseudoEncodingVideoAreaLevel1, - pseudoEncodingVideoAreaLevel100, - pseudoEncodingVideoTimeLevel0, - pseudoEncodingVideoTimeLevel100, - - pseudoEncodingFrameRateLevel10, - pseudoEncodingFrameRateLevel60, - pseudoEncodingMaxVideoResolution, - pseudoEncodingVideoScalingLevel0, - pseudoEncodingVideoScalingLevel9, - pseudoEncodingVideoOutTimeLevel1, - pseudoEncodingVideoOutTimeLevel100, - pseudoEncodingQOI + encodingTight, + encodingZRLE, + encodingHextile, + encodingRRE, + encodingRaw, + pseudoEncodingCompressLevel9, + pseudoEncodingQualityLevel9, + pseudoEncodingFineQualityLevel100, + pseudoEncodingSubsamp16X + //pseudoEncodingWEBP + //pseudoEncodingQOI }; class MockCConnection final : public CConnection { @@ -232,18 +256,19 @@ namespace rfb { // Need to skip the initial handshake and ServerInit setState(RFBSTATE_NORMAL); - // That also means that the reader and writer weren't setup + // That also means that the reader and writer weren't set up setReader(new rfb::CMsgReader(this, &in)); auto &pf = pb->getPF(); CMsgHandler::setPixelFormat(pf); MockCConnection::setDesktopSize(pb->width(), pb->height()); - setFramebuffer(pb); cp.setPF(pf); sc.cp.setPF(pf); sc.setEncodings(std::size(encodings), encodings); + + setFramebuffer(pb); } void setCursor(int width, int height, const Point &hotspot, const rdr::U8 *data, const bool resizing) override { @@ -275,9 +300,6 @@ namespace rfb { screen_layout.remove_screen(0); screen_layout.add_screen(Screen(0, 0, 0, w, h, 0)); - //cp.screenLayout = screen_layout; - //sc.setDesktopSize(w, h, screen_layout); - vlog.info("setDesktopSize"); } void setNewFrame(const AVFrame *frame) { @@ -286,7 +308,7 @@ namespace rfb { const int height = pb->height(); const rfb::Rect rect(0, 0, width, height); - int dstStride; + int dstStride{}; auto *buffer = pb->getBufferRW(rect, &dstStride); const PixelFormat &pf = pb->getPF(); @@ -295,9 +317,7 @@ namespace rfb { const auto *srcData = frame->data[0]; const int srcStride = frame->linesize[0] / 3; // Convert bytes to pixels - vlog.info("Frame stride %d", srcStride); - - // Convert from RGB format to the PixelBuffer's format + // Convert from the RGB format to the PixelBuffer's format pf.bufferFromRGB(buffer, srcData, width, srcStride, height); // Commit changes @@ -317,13 +337,9 @@ namespace rfb { const Region clip(pb->getRect()); - CConnection::framebufferUpdateEnd(); + updates.add_changed(pb->getRect()); - //updates.add_changed(pb->getRect()); updates.getUpdateInfo(&ui, clip); - vlog.info("%d", ui.changed.numRects()); - vlog.info("%d", ui.copied.numRects()); - vlog.info("%lu", ui.copypassed.size()); sc.writeUpdate(ui, pb); } From 07d72ebfbc5a12b12c3bc3d838864805b9e50691 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 24 Apr 2025 13:54:01 +0500 Subject: [PATCH 154/167] KASM-6984 Refactor benchmarking --- common/rfb/ServerCore.cxx | 6 + common/rfb/ServerCore.h | 1 + common/rfb/TightJPEGEncoder.cxx | 6 + common/rfb/VNCServerST.cxx | 4 +- common/rfb/benchmark.cxx | 241 ++++++++++++++---------- common/rfb/benchmark.h | 133 +++---------- common/rfb/ffmpeg.h | 63 +++++++ spec/vncserver_adv_benchmarking_spec.py | 2 +- 8 files changed, 245 insertions(+), 211 deletions(-) create mode 100644 common/rfb/ffmpeg.h diff --git a/common/rfb/ServerCore.cxx b/common/rfb/ServerCore.cxx index bc5a4bd..22f872c 100644 --- a/common/rfb/ServerCore.cxx +++ b/common/rfb/ServerCore.cxx @@ -121,6 +121,12 @@ rfb::StringParameter rfb::Server::benchmark( "Benchmark", "Run extended benchmarks and exit.", ""); + +rfb::StringParameter rfb::Server::benchmarkResults( + "BenchmarkResults", + "The file to save becnhmark results to.", + "Benchmark.xml"); + rfb::IntParameter rfb::Server::dynamicQualityMin ("DynamicQualityMin", "The minimum dynamic JPEG quality, 0 = low, 9 = high", diff --git a/common/rfb/ServerCore.h b/common/rfb/ServerCore.h index a64fc21..82a06b5 100644 --- a/common/rfb/ServerCore.h +++ b/common/rfb/ServerCore.h @@ -89,6 +89,7 @@ namespace rfb { static BoolParameter ignoreClientSettingsKasm; static BoolParameter selfBench; static StringParameter benchmark; + static StringParameter benchmarkResults; static PresetParameter preferBandwidth; static IntParameter webpEncodingTime; }; diff --git a/common/rfb/TightJPEGEncoder.cxx b/common/rfb/TightJPEGEncoder.cxx index 8041b76..8311725 100644 --- a/common/rfb/TightJPEGEncoder.cxx +++ b/common/rfb/TightJPEGEncoder.cxx @@ -25,6 +25,12 @@ #include #include +#include +#include +#include +#include + + using namespace rfb; struct TightJPEGConfiguration { diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index ab6619c..befb1bb 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -83,7 +83,7 @@ EncCache VNCServerST::encCache; void SelfBench(); -void benchmark(const std::string&); +void benchmark(const std::string&, const std::string&); // // -=- VNCServerST Implementation @@ -236,7 +236,7 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) auto *file_name = Server::benchmark.getValueStr(); if (!std::filesystem::exists(file_name)) throw Exception("Benchmarking video file does not exist"); - benchmark(file_name); + benchmark(file_name, Server::benchmarkResults.getValueStr()); } } diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index 1e7c9ae..4708ee7 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -23,8 +23,105 @@ #include #include #include +#include "ServerCore.h" -void benchmark(const std::string &path) { +void report(std::vector &totals, std::vector &timings, + std::vector &stats, const std::string &results_file) { + auto totals_sum = std::accumulate(totals.begin(), totals.end(), 0.); + auto totals_avg = totals_sum / static_cast(totals.size()); + + auto variance = 0.; + for (auto t: totals) + variance += (static_cast(t) - totals_avg) * (static_cast(t) - totals_avg); + + variance /= static_cast(totals.size()); + auto stddev = std::sqrt(variance); + + const auto sum = std::accumulate(timings.begin(), timings.end(), 0.); + const auto size = timings.size(); + const auto average = sum / static_cast(size); + + double median{}; + + std::sort(timings.begin(), timings.end()); + if (size % 2 == 0) + median = static_cast(timings[size / 2]); + else + median = static_cast(timings[size / 2 - 1] + timings[size / 2]) / 2.; + + vlog.info("Mean time encoding frame: %f ms", average); + vlog.info("Median time encoding frame: %f ms", median); + vlog.info("Total time (mean): %f ms", totals_avg); + vlog.info("Total time (stddev): %f ms", stddev); + + uint32_t jpeg_sum{}, jpeg_rects{}, webp_sum{}, webp_rects{}; + uint64_t bytes{}; + + for (const auto &item: stats) { + jpeg_sum += item.jpeg_stats.ms; + jpeg_rects += item.jpeg_stats.rects; + webp_sum += item.webp_stats.ms; + webp_rects += item.webp_stats.rects; + bytes += item.bytes; + } + + auto jpeg_ms = jpeg_sum / static_cast(stats.size()); + vlog.info("JPEG stats: %f ms", jpeg_ms); + jpeg_rects /= stats.size(); + vlog.info("JPEG stats: %u rects", jpeg_rects); + auto webp_ms = webp_sum / static_cast(stats.size()); + webp_rects /= stats.size(); + bytes /= stats.size(); + vlog.info("WebP stats: %f ms", webp_ms); + vlog.info("WebP stats: %u rects", webp_rects); + vlog.info("Total bytes sent: %lu bytes", bytes); + + tinyxml2::XMLDocument doc; + + auto *test_suit = doc.NewElement("testsuite"); + test_suit->SetAttribute("name", "Benchmark"); + + doc.InsertFirstChild(test_suit); + auto total_tests{0}; + + auto add_benchmark_item = [&doc, &test_suit, &total_tests](const char *name, auto value) { + auto *test_case = doc.NewElement("testcase"); + test_case->SetAttribute("name", name); + test_case->SetAttribute("file", value); + test_case->SetAttribute("runs", 1); + test_case->SetAttribute("classname", "KasmVNC"); + + auto *props = doc.NewElement("properties"); + + auto *prop = doc.NewElement("property"); + prop->SetAttribute("name", name); + props->InsertEndChild(prop); + + prop = doc.NewElement("property"); + prop->SetAttribute("value", value); + props->InsertEndChild(prop); + + test_case->InsertEndChild(props); + test_suit->InsertEndChild(test_case); + + ++total_tests; + }; + + add_benchmark_item("Average time encoding frame, ms", average); + add_benchmark_item("Median time encoding frame, ms", median); + add_benchmark_item("Total time encoding, ms", totals_avg); + add_benchmark_item("Total time encoding, stddev", stddev); + add_benchmark_item("Mean JPEG stats, ms", jpeg_ms); + add_benchmark_item("Mean JPEG stats, rects", jpeg_rects); + add_benchmark_item("Mean WebP stats, ms", webp_ms); + add_benchmark_item("Mean WebP stats, rects", webp_rects); + + add_benchmark_item("Data sent, KBs", bytes / 1024); + + doc.SaveFile(results_file.c_str()); +} + +void benchmark(const std::string &path, const std::string &results_file) { AVFormatContext *format_ctx = nullptr; vlog.info("Benchmarking with video file %s", path.c_str()); @@ -98,123 +195,69 @@ void benchmark(const std::string &path) { rgb_frame->height = codec_ctx->height; static const rfb::PixelFormat pf{32, 24, false, true, 0xFF, 0xFF, 0xFF, 0, 8, 16}; + std::vector encodings{std::begin(rfb::default_encodings), std::end(rfb::default_encodings)}; - auto *pb = new rfb::ManagedPixelBuffer{pf, rgb_frame->width, rgb_frame->height}; - rfb::MockCConnection connection{pb}; + // if (rfb::Server::WebPEnabled) + // encodings.push_back(rfb::pseudoEncodingWEBP); if (av_frame_get_buffer(rgb_frame, 0) != 0) throw std::runtime_error("Could not allocate frame data"); - uint64_t frames{}; + constexpr auto runs = 20; + std::vector totals(runs, 0); + std::vector stats(runs); const size_t total_frame_count = format_ctx->streams[video_stream_idx]->nb_frames; + std::vector timings(total_frame_count > 0 ? total_frame_count * runs : 2048, 0); + uint64_t frames{}; - std::vector timings(total_frame_count > 0 ? total_frame_count : 2048, 0); + for (int run = 0; run < runs; ++run) { + auto *pb = new rfb::ManagedPixelBuffer{pf, rgb_frame->width, rgb_frame->height}; + rfb::MockCConnection connection{encodings, pb}; - vlog.info("Reading frames..."); - while (av_read_frame(format_ctx, packet) == 0) { - if (packet->stream_index == video_stream_idx) { - if (avcodec_send_packet(codec_ctx, packet) == 0) { - while (avcodec_receive_frame(codec_ctx, frame) == 0) { - // Convert to RGB - sws_scale(sws_ctx, frame->data, frame->linesize, 0, frame->height, - rgb_frame->data, rgb_frame->linesize); + uint64_t total{}; - connection.framebufferUpdateStart(); - connection.setNewFrame(rgb_frame); - using namespace std::chrono; + vlog.info("RUN %d. Reading frames...", run); + while (av_read_frame(format_ctx, packet) == 0) { + if (packet->stream_index == video_stream_idx) { + if (avcodec_send_packet(codec_ctx, packet) == 0) { + while (avcodec_receive_frame(codec_ctx, frame) == 0) { + // Convert to RGB + sws_scale(sws_ctx, frame->data, frame->linesize, 0, frame->height, + rgb_frame->data, rgb_frame->linesize); - auto now = high_resolution_clock::now(); - connection.framebufferUpdateEnd(); - const auto duration = duration_cast(high_resolution_clock::now() - now).count(); + connection.framebufferUpdateStart(); + connection.setNewFrame(rgb_frame); + using namespace std::chrono; - vlog.info("Frame took %lu ms", duration); + auto now = high_resolution_clock::now(); + connection.framebufferUpdateEnd(); + const auto duration = duration_cast(high_resolution_clock::now() - now).count(); - // auto [jpeg_stats, webp_stats, bytes, udp_bytes] = connection.getStats(); - //vlog.info("JPEG stats: %d ms", jpeg_stats.ms); - //vlog.info("JPEG stats: %d rects", jpeg_stats.rects); + //vlog.info("Frame took %lu ms", duration); - //vlog.info("WebP stats: %d ms", webp_stats.ms); - // vlog.info("WebP stats: %d rects", webp_stats.rects); - - timings[frames++] = duration; + timings[frames++] = duration; + total += duration; + } } } + av_packet_unref(packet); } - av_packet_unref(packet); + vlog.info("RUN %d. Done reading frames...", run); + + if (av_seek_frame(format_ctx, video_stream_idx, 0, AVSEEK_FLAG_BACKWARD) < 0) + throw std::runtime_error("Could not seek to start of video"); + + avcodec_flush_buffers(codec_ctx); + + totals[run] = total; + stats[run] = connection.getStats(); + vlog.info("RUN %d. Bytes sent %lu..", run, stats[run].bytes); } - vlog.info("Done reading frames..."); - if (frames > 0) { - timings.reserve(frames + 1); + if (frames > 0) + report(totals, timings, stats, results_file); - const auto sum = std::accumulate(timings.begin(), timings.end(), 0.); - const auto size = timings.size(); - const auto average = sum / static_cast(size); - - double median{}; - - std::sort(timings.begin(), timings.end()); - if (size % 2 == 0) - median = static_cast(timings[size / 2]); - else - median = static_cast(timings[size / 2 - 1] + timings[size / 2]) / 2.; - - auto [jpeg_stats, webp_stats, bytes, udp_bytes] = connection.getStats(); - - vlog.info("Average time encoding frame: %f ns", average); - vlog.info("Median time encoding frame: %f ns", median); - vlog.info("Total time: %f ms", sum); - vlog.info("JPEG stats: %d ms", jpeg_stats.ms); - vlog.info("JPEG stats: %d rects", jpeg_stats.rects); - vlog.info("WebP stats: %d ms", webp_stats.ms); - vlog.info("WebP stats: %d rects", webp_stats.rects); - vlog.info("Total bytes sent: %lu bytes", bytes); - - tinyxml2::XMLDocument doc; - - auto *test_suit = doc.NewElement("testsuite"); - test_suit->SetAttribute("name", "Benchmark"); - - doc.InsertFirstChild(test_suit); - - constexpr auto div = 1. / (1000); - auto total_tests{0}; - - auto add_benchmark_item = [&doc, &test_suit, &total_tests](const char *name, auto value) { - auto *test_case = doc.NewElement("testcase"); - test_case->SetAttribute("name", name); - test_case->SetAttribute("file", value); - test_case->SetAttribute("runs", 1); - test_case->SetAttribute("classname", "KasmVNC"); - - auto *props = doc.NewElement("properties"); - - auto *prop = doc.NewElement("property"); - prop->SetAttribute("name", name); - props->InsertEndChild(prop); - - prop = doc.NewElement("property"); - prop->SetAttribute("value", value); - props->InsertEndChild(prop); - - test_case->InsertEndChild(props); - test_suit->InsertEndChild(test_case); - - ++total_tests; - }; - - add_benchmark_item("Average time encoding frame, ms", average * div); - add_benchmark_item("Median time encoding frame, ms", median * div); - add_benchmark_item("Total time encoding, ms", sum * div); - - add_benchmark_item("Data sent, KBs", bytes / 1024); - - //ss.flush(); - //ss << "KBytes sent (UDP): " << udp_bytes / 1024; - //add_benchmark_item(ss.str().c_str(), 0); - - doc.SaveFile("Benchmark.xml"); - } + avcodec_close(codec_ctx); exit(0); } diff --git a/common/rfb/benchmark.h b/common/rfb/benchmark.h index 72a3914..0cb1558 100644 --- a/common/rfb/benchmark.h +++ b/common/rfb/benchmark.h @@ -18,8 +18,7 @@ #pragma once -#include -#include +#include #include #include @@ -30,58 +29,30 @@ #include "LogWriter.h" #include "screenTypes.h" #include "SMsgWriter.h" +#include "ffmpeg.h" namespace rdr { class FileInStream; } -extern "C" { -#include -#include -#include -} - static rfb::LogWriter vlog("Benchmarking"); -struct AVFormatContextDeleter { - void operator()(AVFormatContext *ctx) const { - avformat_close_input(&ctx); - } -}; - -struct AVCodecContextDeleter { - void operator()(AVCodecContext *ctx) const { - avcodec_free_context(&ctx); - } -}; - -struct AVFrameDeleter { - void operator()(AVFrame *frame) const { - av_frame_free(&frame); - } -}; - -struct SwsContextDeleter { - void operator()(SwsContext *ctx) const { - sws_freeContext(ctx); - } -}; - -struct PacketDeleter { - void operator()(AVPacket *packet) const { - av_packet_free(&packet); - } -}; - -using FormatCtxGuard = std::unique_ptr; -using CodecCtxGuard = std::unique_ptr; -using FrameGuard = std::unique_ptr; -using SwsContextGuard = std::unique_ptr; -using PacketGuard = std::unique_ptr; - - namespace rfb { - class MockBufferStream : public rdr::BufferedInStream { + static constexpr rdr::S32 default_encodings[] = { + encodingTight, + encodingZRLE, + encodingHextile, + encodingRRE, + encodingRaw, + pseudoEncodingCompressLevel9, + pseudoEncodingQualityLevel9, + pseudoEncodingFineQualityLevel100, + pseudoEncodingSubsamp16X + //pseudoEncodingWEBP + //pseudoEncodingQOI + }; + + class MockBufferStream final : public rdr::BufferedInStream { bool fillBuffer(size_t maxSize, bool wait) override { return true; } @@ -131,9 +102,6 @@ namespace rfb { void writeUpdate(const UpdateInfo &ui, const PixelBuffer *pb) { //manager.pruneLosslessRefresh(Region(pb->getRect())); - bytes += out.length(); - udp_bytes += udps.length(); - cache.clear(); manager.clearEncodingTime(); @@ -145,45 +113,6 @@ namespace rfb { } } - void writeNoDataUpdate() { - if (!writer()->needNoDataUpdate()) - return; - - writer()->writeNoDataUpdate(); - } - - void WriteDataUpdate() { - Region req, pending; - - if (req.is_empty()) - return; - - if (!pending.is_empty()) { - UpdateInfo ui; - // However, we might still be able to send a lossless refresh - req.assign_subtract(pending); - req.assign_subtract(ui.changed); - req.assign_subtract(ui.copied); - - ui.changed.clear(); - ui.copied.clear(); - } - } - - void writeFramebufferUpdate() { - manager.clearEncodingTime(); - - if (state() != RFBSTATE_NORMAL) - return; - - // First, take care of any updates that cannot contain framebuffer data - // changes. - writeNoDataUpdate(); - - // Then real data (if possible) - WriteDataUpdate(); - } - void setDesktopSize(int fb_width, int fb_height, const ScreenSet &layout) override { cp.width = fb_width; @@ -224,8 +153,8 @@ namespace rfb { return manager.webpstats; } - uint64_t bytes{}; - uint64_t udp_bytes{}; + [[nodiscard]] auto bytes() { return out.length(); } + [[nodiscard]] auto udp_bytes() { return udps.length(); } protected: MockStream out{}; @@ -235,23 +164,9 @@ namespace rfb { EncodeManager manager{this, &cache}; }; - static constexpr rdr::S32 encodings[] = { - encodingTight, - encodingZRLE, - encodingHextile, - encodingRRE, - encodingRaw, - pseudoEncodingCompressLevel9, - pseudoEncodingQualityLevel9, - pseudoEncodingFineQualityLevel100, - pseudoEncodingSubsamp16X - //pseudoEncodingWEBP - //pseudoEncodingQOI - }; - class MockCConnection final : public CConnection { public: - explicit MockCConnection(ManagedPixelBuffer *pb) { + explicit MockCConnection(const std::vector& encodings, ManagedPixelBuffer *pb) { setStreams(&in, nullptr); // Need to skip the initial handshake and ServerInit @@ -266,7 +181,7 @@ namespace rfb { cp.setPF(pf); sc.cp.setPF(pf); - sc.setEncodings(std::size(encodings), encodings); + sc.setEncodings(std::size(encodings), encodings.data()); setFramebuffer(pb); } @@ -284,12 +199,12 @@ namespace rfb { uint64_t udp_bytes; }; - [[nodiscard]] stats_t getStats() const { + [[nodiscard]] stats_t getStats() { return { sc.getJpegStats(), sc.getWebPStats(), - sc.bytes, - sc.udp_bytes + sc.bytes(), + sc.udp_bytes() }; } diff --git a/common/rfb/ffmpeg.h b/common/rfb/ffmpeg.h new file mode 100644 index 0000000..fa3539c --- /dev/null +++ b/common/rfb/ffmpeg.h @@ -0,0 +1,63 @@ +/* Copyright (C) 2025 Kasm Technologies Corp +* + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ + +#pragma once + +#include + +extern "C" { +#include +#include +#include +} + +struct AVFormatContextDeleter { + void operator()(AVFormatContext *ctx) const { + avformat_close_input(&ctx); + } +}; + +struct AVCodecContextDeleter { + void operator()(AVCodecContext *ctx) const { + avcodec_free_context(&ctx); + } +}; + +struct AVFrameDeleter { + void operator()(AVFrame *frame) const { + av_frame_free(&frame); + } +}; + +struct SwsContextDeleter { + void operator()(SwsContext *ctx) const { + sws_freeContext(ctx); + } +}; + +struct PacketDeleter { + void operator()(AVPacket *packet) const { + av_packet_free(&packet); + } +}; + +using FormatCtxGuard = std::unique_ptr; +using CodecCtxGuard = std::unique_ptr; +using FrameGuard = std::unique_ptr; +using SwsContextGuard = std::unique_ptr; +using PacketGuard = std::unique_ptr; diff --git a/spec/vncserver_adv_benchmarking_spec.py b/spec/vncserver_adv_benchmarking_spec.py index 2b805ca..8e4b10f 100644 --- a/spec/vncserver_adv_benchmarking_spec.py +++ b/spec/vncserver_adv_benchmarking_spec.py @@ -9,7 +9,7 @@ with description("Benchmarking"): kill_xvnc() with it("runs benchmarks"): run_cmd("wget --no-check-certificate https://kasmweb-build-artifacts.s3.us-east-1.amazonaws.com/kasmvnc/static/127072-737747495_small.mp4 -O /tmp/video.mp4") - completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -Benchmark /tmp/video.mp4") + completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -Benchmark /tmp/video.mp4 -VideoArea 100") command = '''sed -i "s/KasmVNC/$(grep -E '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"') $(grep -E '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2 | tr -d '"')/g" Benchmark.xml''' run_cmd(command) expect(completed_process.returncode).to(equal(0)) From 2237c97a5e6251e9baa6e0901f3ad31417a7a3ea Mon Sep 17 00:00:00 2001 From: El Date: Thu, 24 Apr 2025 18:23:56 +0500 Subject: [PATCH 155/167] KASM-6984 Refactor benchmarking --- common/rfb/benchmark.cxx | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index 4708ee7..32aa659 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -84,39 +84,30 @@ void report(std::vector &totals, std::vector &timings, doc.InsertFirstChild(test_suit); auto total_tests{0}; - auto add_benchmark_item = [&doc, &test_suit, &total_tests](const char *name, auto value) { + auto add_benchmark_item = [&doc, &test_suit, &total_tests](const char *name, auto time_value, auto other_value) { auto *test_case = doc.NewElement("testcase"); test_case->SetAttribute("name", name); - test_case->SetAttribute("file", value); + test_case->SetAttribute("file", other_value); + test_case->SetAttribute("time", time_value); test_case->SetAttribute("runs", 1); test_case->SetAttribute("classname", "KasmVNC"); - auto *props = doc.NewElement("properties"); - - auto *prop = doc.NewElement("property"); - prop->SetAttribute("name", name); - props->InsertEndChild(prop); - - prop = doc.NewElement("property"); - prop->SetAttribute("value", value); - props->InsertEndChild(prop); - - test_case->InsertEndChild(props); test_suit->InsertEndChild(test_case); ++total_tests; }; - add_benchmark_item("Average time encoding frame, ms", average); - add_benchmark_item("Median time encoding frame, ms", median); - add_benchmark_item("Total time encoding, ms", totals_avg); - add_benchmark_item("Total time encoding, stddev", stddev); - add_benchmark_item("Mean JPEG stats, ms", jpeg_ms); - add_benchmark_item("Mean JPEG stats, rects", jpeg_rects); - add_benchmark_item("Mean WebP stats, ms", webp_ms); - add_benchmark_item("Mean WebP stats, rects", webp_rects); + constexpr auto mult = 1 / 1000.; + add_benchmark_item("Average time encoding frame, ms", average * mult, ""); + add_benchmark_item("Median time encoding frame, ms", median * mult, ""); + add_benchmark_item("Total time encoding, ms", 0, totals_avg); + add_benchmark_item("Total time encoding, stddev", 0, stddev); + add_benchmark_item("Mean JPEG stats, ms", jpeg_ms, ""); + add_benchmark_item("Mean JPEG stats, rects", 0., jpeg_rects); + add_benchmark_item("Mean WebP stats, ms", webp_ms, ""); + add_benchmark_item("Mean WebP stats, rects", 0, webp_rects); - add_benchmark_item("Data sent, KBs", bytes / 1024); + add_benchmark_item("Data sent, KBs", 0, bytes / 1024); doc.SaveFile(results_file.c_str()); } From f037c3bae1671b07f06347bff66d8d4a0c2860e6 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 28 Apr 2025 23:18:46 +0500 Subject: [PATCH 156/167] KASM-6984 Updated copyright information and performed minor code cleanup to remove unused code and improve readability. --- common/rfb/benchmark.cxx | 2 ++ common/rfb/benchmark.h | 20 ++++---------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index 32aa659..eb5c780 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -242,6 +242,8 @@ void benchmark(const std::string &path, const std::string &results_file) { totals[run] = total; stats[run] = connection.getStats(); + vlog.info("JPEG stats: %u ms", stats[run].jpeg_stats.ms); + vlog.info("WebP stats: %u ms", stats[run].webp_stats.ms); vlog.info("RUN %d. Bytes sent %lu..", run, stats[run].bytes); } diff --git a/common/rfb/benchmark.h b/common/rfb/benchmark.h index 0cb1558..c834dfd 100644 --- a/common/rfb/benchmark.h +++ b/common/rfb/benchmark.h @@ -1,4 +1,6 @@ -/* Copyright (C) 2025 Kasm Technologies Corp +/* Copyright 2015 Pierre Ossman for Cendio AB + * Copyright (C) 2015 D. R. Commander. All Rights Reserved. + * Copyright (C) 2025 Kasm Technologies Corp * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,10 +33,6 @@ #include "SMsgWriter.h" #include "ffmpeg.h" -namespace rdr { - class FileInStream; -} - static rfb::LogWriter vlog("Benchmarking"); namespace rfb { @@ -100,9 +98,7 @@ namespace rfb { ~MockSConnection() override = default; void writeUpdate(const UpdateInfo &ui, const PixelBuffer *pb) { - //manager.pruneLosslessRefresh(Region(pb->getRect())); - - cache.clear(); + cache.clear(); manager.clearEncodingTime(); if (!ui.is_empty()) { @@ -191,7 +187,6 @@ namespace rfb { ~MockCConnection() override = default; - struct stats_t { EncodeManager::codecstats_t jpeg_stats; EncodeManager::codecstats_t webp_stats; @@ -240,8 +235,6 @@ namespace rfb { } void framebufferUpdateStart() override { - CConnection::framebufferUpdateStart(); - updates.clear(); } @@ -249,7 +242,6 @@ namespace rfb { const PixelBuffer *pb = getFramebuffer(); UpdateInfo ui; - const Region clip(pb->getRect()); updates.add_changed(pb->getRect()); @@ -259,10 +251,6 @@ namespace rfb { } void dataRect(const Rect &r, int encoding) override { - CConnection::dataRect(r, encoding); - - if (encoding != encodingCopyRect) // FIXME - updates.add_changed(Region(r)); } void setColourMapEntries(int, int, rdr::U16 *) override { From 148f22f05f848643af5f3a9af89646d3255f1c44 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 28 Apr 2025 23:40:57 +0500 Subject: [PATCH 157/167] KASM-6984 Update man pages --- unix/xserver/hw/vnc/Xvnc.man | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/unix/xserver/hw/vnc/Xvnc.man b/unix/xserver/hw/vnc/Xvnc.man index c23bccd..206784c 100644 --- a/unix/xserver/hw/vnc/Xvnc.man +++ b/unix/xserver/hw/vnc/Xvnc.man @@ -574,6 +574,16 @@ When \fBNoClipboard\fP parameter is set, allowing override of \fBSendCutText\fP and \fBAcceptCutText\fP has no effect. Default is \fBdesktop,AcceptPointerEvents,SendCutText,AcceptCutText,SendPrimary,SetPrimary\fP. +. +TP +.B -Benchmark +Run the built-in benchmarking routines on the specified video file and exit. +When this option is used, benchmarking results can be saved to a file specified by the \fB-BenchmarkResults\fP option; otherwise, the results are saved to \fBBenchmark.xml\fP by default. +. +.TP +.B -BenchmarkResults +Save the benchmarking results to the specified file. +Use this option together with \fB-Benchmark\fP to output the report to a custom file. .SH USAGE WITH INETD By configuring the \fBinetd\fP(1) service appropriately, Xvnc can be launched From f64dc1a25780894dff0aaa281a3820e62119b731 Mon Sep 17 00:00:00 2001 From: El Date: Tue, 29 Apr 2025 15:29:38 +0500 Subject: [PATCH 158/167] KASM-6984 Add ffmpeg-libs to required packages --- oracle/kasmvncserver.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oracle/kasmvncserver.spec b/oracle/kasmvncserver.spec index 85751bd..e08897a 100644 --- a/oracle/kasmvncserver.spec +++ b/oracle/kasmvncserver.spec @@ -7,7 +7,7 @@ License: GPLv2+ URL: https://github.com/kasmtech/KasmVNC BuildRequires: rsync -Requires: xorg-x11-xauth, xorg-x11-xkb-utils, xkeyboard-config, xorg-x11-server-utils, openssl, perl, perl-Switch, perl-YAML-Tiny, perl-Hash-Merge-Simple, perl-Scalar-List-Utils, perl-List-MoreUtils, perl-Try-Tiny, perl-DateTime-TimeZone, hostname, mesa-libgbm, libxshmfence +Requires: xorg-x11-xauth, xorg-x11-xkb-utils, xkeyboard-config, xorg-x11-server-utils, openssl, perl, perl-Switch, perl-YAML-Tiny, perl-Hash-Merge-Simple, perl-Scalar-List-Utils, perl-List-MoreUtils, perl-Try-Tiny, perl-DateTime-TimeZone, hostname, mesa-libgbm, libxshmfence, ffmpeg-libs Conflicts: tigervnc-server, tigervnc-server-minimal %description From 415607ea42894e92a15bf03f03516d9c1f8fde04 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 1 May 2025 04:07:47 +0500 Subject: [PATCH 159/167] KASM-6984 Moved to a dynamic library load --- common/rfb/CMakeLists.txt | 3 +- common/rfb/VNCServerST.cxx | 7 +- common/rfb/benchmark.cxx | 421 ++++++++++++++++++++---------- common/rfb/benchmark.h | 250 +----------------- common/rfb/ffmpeg.cxx | 210 +++++++++++++++ common/rfb/ffmpeg.h | 165 +++++++++--- unix/xserver/hw/vnc/vncExtInit.cc | 2 +- 7 files changed, 648 insertions(+), 410 deletions(-) create mode 100644 common/rfb/ffmpeg.cxx diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt index 317fe2b..a55ea60 100644 --- a/common/rfb/CMakeLists.txt +++ b/common/rfb/CMakeLists.txt @@ -68,6 +68,7 @@ set(RFB_SOURCES encodings.cxx util.cxx xxhash.c + ffmpeg.cxx ) if (UNIX) @@ -143,7 +144,7 @@ target_include_directories(rfb PRIVATE ${FFMPEG_INCLUDE_DIRS} ) -target_link_libraries(rfb PRIVATE ${RFB_LIBRARIES} tinyxml2_objs ${FFMPEG_LIBRARIES}) +target_link_libraries(rfb PRIVATE ${RFB_LIBRARIES} tinyxml2_objs) if (UNIX) libtool_create_control_file(rfb) diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index befb1bb..94979a9 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -48,8 +48,8 @@ // otherwise blacklisted connections might be "forgotten". -#include -#include +#include +#include #include #include @@ -74,6 +74,7 @@ #include #include #include +#include using namespace rfb; @@ -83,7 +84,7 @@ EncCache VNCServerST::encCache; void SelfBench(); -void benchmark(const std::string&, const std::string&); +void benchmark(std::string_view, std::string_view); // // -=- VNCServerST Implementation diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index eb5c780..4218d91 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -1,4 +1,6 @@ -/* Copyright (C) 2025 Kasm Technologies Corp +/* Copyright 2015 Pierre Ossman for Cendio AB + * Copyright (C) 2015 D. R. Commander. All Rights Reserved. + * Copyright (C) 2025 Kasm Technologies Corp * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,16 +19,253 @@ */ #include "benchmark.h" -#include -#include +#include #include #include #include #include +#include + #include "ServerCore.h" +#include + +#include "EncCache.h" +#include "EncodeManager.h" +#include "SConnection.h" +#include "screenTypes.h" +#include "SMsgWriter.h" +#include "UpdateTracker.h" +#include "rdr/BufferedInStream.h" +#include "rdr/OutStream.h" +#include "ffmpeg.h" + +namespace benchmarking { + class MockBufferStream final : public rdr::BufferedInStream { + bool fillBuffer(size_t maxSize, bool wait) override { + return true; + } + }; + + class MockStream final : public rdr::OutStream { + public: + MockStream() { + offset = 0; + ptr = buf; + end = buf + sizeof(buf); + } + + private: + void overrun(size_t needed) override { + assert(end >= ptr); + if (needed > static_cast(end - ptr)) + flush(); + } + + public: + size_t length() override { + flush(); + return offset; + } + + void flush() override { + offset += ptr - buf; + ptr = buf; + } + + private: + ptrdiff_t offset; + rdr::U8 buf[8192]{}; + }; + + class MockSConnection final : public rfb::SConnection { + public: + MockSConnection() { + setStreams(nullptr, &out); + + setWriter(new rfb::SMsgWriter(&cp, &out, &udps)); + } + + ~MockSConnection() override = default; + + void writeUpdate(const rfb::UpdateInfo &ui, const rfb::PixelBuffer *pb) { + cache.clear(); + + manager.clearEncodingTime(); + if (!ui.is_empty()) { + manager.writeUpdate(ui, pb, nullptr); + } else { + rfb::Region region{pb->getRect()}; + manager.writeLosslessRefresh(region, pb, nullptr, 2000); + } + } + + void setDesktopSize(int fb_width, int fb_height, + const rfb::ScreenSet &layout) override { + cp.width = fb_width; + cp.height = fb_height; + cp.screenLayout = layout; + + writer()->writeExtendedDesktopSize(rfb::reasonServer, 0, cp.width, cp.height, + cp.screenLayout); + } + + void sendStats(const bool toClient) override { + } + + [[nodiscard]] bool canChangeKasmSettings() const override { + return false; + } + + void udpUpgrade(const char *resp) override { + } + + void udpDowngrade(const bool) override { + } + + void subscribeUnixRelay(const char *name) override { + } + + void unixRelay(const char *name, const rdr::U8 *buf, const unsigned len) override { + } + + void handleFrameStats(rdr::U32 all, rdr::U32 render) override { + } + + [[nodiscard]] auto getJpegStats() const { + return manager.jpegstats; + } + + [[nodiscard]] auto getWebPStats() const { + return manager.webpstats; + } + + [[nodiscard]] auto bytes() { return out.length(); } + [[nodiscard]] auto udp_bytes() { return udps.length(); } + + protected: + MockStream out{}; + MockStream udps{}; + + EncCache cache{}; + EncodeManager manager{this, &cache}; + }; + + class MockCConnection final : public MockTestConnection { + public: + explicit MockCConnection(const std::vector &encodings, rfb::ManagedPixelBuffer *pb) { + setStreams(&in, nullptr); + + // Need to skip the initial handshake and ServerInit + setState(RFBSTATE_NORMAL); + // That also means that the reader and writer weren't set up + setReader(new rfb::CMsgReader(this, &in)); + auto &pf = pb->getPF(); + CMsgHandler::setPixelFormat(pf); + + MockCConnection::setDesktopSize(pb->width(), pb->height()); + + cp.setPF(pf); + + sc.cp.setPF(pf); + sc.setEncodings(std::size(encodings), encodings.data()); + + setFramebuffer(pb); + } + + void setCursor(int width, int height, const rfb::Point &hotspot, const rdr::U8 *data, + const bool resizing) override { + } + + ~MockCConnection() override = default; + + struct stats_t { + EncodeManager::codecstats_t jpeg_stats; + EncodeManager::codecstats_t webp_stats; + uint64_t bytes; + uint64_t udp_bytes; + }; + + [[nodiscard]] stats_t getStats() { + return { + sc.getJpegStats(), + sc.getWebPStats(), + sc.bytes(), + sc.udp_bytes() + }; + } + + void setDesktopSize(int w, int h) override { + CConnection::setDesktopSize(w, h); + + if (screen_layout.num_screens()) + screen_layout.remove_screen(0); + + screen_layout.add_screen(rfb::Screen(0, 0, 0, w, h, 0)); + } + + void setNewFrame(const AVFrame *frame) override { + auto *pb = getFramebuffer(); + const int width = pb->width(); + const int height = pb->height(); + const rfb::Rect rect(0, 0, width, height); + + int dstStride{}; + auto *buffer = pb->getBufferRW(rect, &dstStride); + + const rfb::PixelFormat &pf = pb->getPF(); + + // Source data and stride from FFmpeg + const auto *srcData = frame->data[0]; + const int srcStride = frame->linesize[0] / 3; // Convert bytes to pixels + + // Convert from the RGB format to the PixelBuffer's format + pf.bufferFromRGB(buffer, srcData, width, srcStride, height); + + // Commit changes + pb->commitBufferRW(rect); + } + + void framebufferUpdateStart() override { + updates.clear(); + } + + void framebufferUpdateEnd() override { + const rfb::PixelBuffer *pb = getFramebuffer(); + + rfb::UpdateInfo ui; + const rfb::Region clip(pb->getRect()); + + updates.add_changed(pb->getRect()); + + updates.getUpdateInfo(&ui, clip); + sc.writeUpdate(ui, pb); + } + + void dataRect(const rfb::Rect &r, int encoding) override { + } + + void setColourMapEntries(int, int, rdr::U16 *) override { + } + + void bell() override { + } + + void serverCutText(const char *, rdr::U32) override { + } + + void serverCutText(const char *str) override { + } + + protected: + MockBufferStream in; + rfb::ScreenSet screen_layout; + rfb::SimpleUpdateTracker updates; + MockSConnection sc; + }; +} void report(std::vector &totals, std::vector &timings, - std::vector &stats, const std::string &results_file) { + std::vector &stats, const std::string_view results_file) { auto totals_sum = std::accumulate(totals.begin(), totals.end(), 0.); auto totals_avg = totals_sum / static_cast(totals.size()); @@ -109,148 +348,52 @@ void report(std::vector &totals, std::vector &timings, add_benchmark_item("Data sent, KBs", 0, bytes / 1024); - doc.SaveFile(results_file.c_str()); + doc.SaveFile(results_file.data()); } -void benchmark(const std::string &path, const std::string &results_file) { - AVFormatContext *format_ctx = nullptr; +void benchmark(std::string_view path, const std::string_view results_file) { + try { + vlog.info("Benchmarking with video file %s", path.data()); + FFmpegFrameFeeder frame_feeder{}; + frame_feeder.open(path); - vlog.info("Benchmarking with video file %s", path.c_str()); + static const rfb::PixelFormat pf{32, 24, false, true, 0xFF, 0xFF, 0xFF, 0, 8, 16}; + const std::vector encodings{ + std::begin(benchmarking::default_encodings), std::end(benchmarking::default_encodings) + }; - if (avformat_open_input(&format_ctx, path.c_str(), nullptr, nullptr) < 0) - throw std::runtime_error("Could not open video file"); + // if (rfb::Server::WebPEnabled) + // encodings.push_back(rfb::pseudoEncodingWEBP); - FormatCtxGuard format_ctx_guard{format_ctx}; + constexpr auto runs = 20; + std::vector totals(runs, 0); + std::vector stats(runs); + std::vector timings{}; + auto [width, height] = frame_feeder.get_frame_dimensions(); - // Find stream info - if (avformat_find_stream_info(format_ctx, nullptr) < 0) - throw std::runtime_error("Could not find stream info"); + for (int run = 0; run < runs; ++run) { + auto *pb = new rfb::ManagedPixelBuffer{pf, width, height}; + benchmarking::MockCConnection connection{encodings, pb}; - // Find video stream - int video_stream_idx = -1; - for (uint32_t i = 0; i < format_ctx->nb_streams; ++i) { - if (format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - video_stream_idx = static_cast(i); - break; + vlog.info("RUN %d. Reading frames...", run); + auto play_stats = frame_feeder.play(&connection); + vlog.info("RUN %d. Done reading frames...", run); + + timings.insert(timings.end(), play_stats.timings.begin(), play_stats.timings.end()); + + totals[run] = play_stats.total; + stats[run] = connection.getStats(); + vlog.info("JPEG stats: %u ms", stats[run].jpeg_stats.ms); + vlog.info("WebP stats: %u ms", stats[run].webp_stats.ms); + vlog.info("RUN %d. Bytes sent %lu..", run, stats[run].bytes); } + + if (!timings.empty()) + report(totals, timings, stats, results_file); + + exit(0); + } catch (std::exception &e) { + vlog.error("Benchmarking failed: %s", e.what()); + exit(1); } - - if (video_stream_idx == -1) - throw std::runtime_error("No video stream found"); - - // Get codec parameters and decoder - const auto *codec_parameters = format_ctx->streams[video_stream_idx]->codecpar; - const auto *codec = avcodec_find_decoder(codec_parameters->codec_id); - if (!codec) - throw std::runtime_error("Codec not found"); - - const CodecCtxGuard codex_ctx_guard{avcodec_alloc_context3(codec)}; - auto *codec_ctx = codex_ctx_guard.get(); - - if (!codec_ctx || avcodec_parameters_to_context(codec_ctx, codec_parameters) < 0) - throw std::runtime_error("Failed to set up codec context"); - - if (avcodec_open2(codec_ctx, codec, nullptr) < 0) - throw std::runtime_error("Could not open codec"); - - // Allocate frame and packet - const FrameGuard frame_guard{av_frame_alloc()}; - auto *frame = frame_guard.get(); - - const PacketGuard packet_guard{av_packet_alloc()}; - auto *packet = packet_guard.get(); - - if (!frame || !packet) - throw std::runtime_error("Could not allocate frame or packet"); - - // Scaling context to convert to RGB24 - SwsContext *sws_ctx = sws_getContext( - codec_ctx->width, codec_ctx->height, codec_ctx->pix_fmt, - codec_ctx->width, codec_ctx->height, AV_PIX_FMT_RGB24, - SWS_BILINEAR, nullptr, nullptr, nullptr - ); - - if (!sws_ctx) - throw std::runtime_error("Could not create scaling context"); - - SwsContextGuard sws_ctx_guard{sws_ctx}; - - const FrameGuard rgb_frame_guard{av_frame_alloc()}; - auto *rgb_frame = rgb_frame_guard.get(); - - if (!rgb_frame) - throw std::runtime_error("Could not allocate frame"); - - rgb_frame->format = AV_PIX_FMT_RGB24; - rgb_frame->width = codec_ctx->width; - rgb_frame->height = codec_ctx->height; - - static const rfb::PixelFormat pf{32, 24, false, true, 0xFF, 0xFF, 0xFF, 0, 8, 16}; - std::vector encodings{std::begin(rfb::default_encodings), std::end(rfb::default_encodings)}; - - // if (rfb::Server::WebPEnabled) - // encodings.push_back(rfb::pseudoEncodingWEBP); - - if (av_frame_get_buffer(rgb_frame, 0) != 0) - throw std::runtime_error("Could not allocate frame data"); - - constexpr auto runs = 20; - std::vector totals(runs, 0); - std::vector stats(runs); - const size_t total_frame_count = format_ctx->streams[video_stream_idx]->nb_frames; - std::vector timings(total_frame_count > 0 ? total_frame_count * runs : 2048, 0); - uint64_t frames{}; - - for (int run = 0; run < runs; ++run) { - auto *pb = new rfb::ManagedPixelBuffer{pf, rgb_frame->width, rgb_frame->height}; - rfb::MockCConnection connection{encodings, pb}; - - uint64_t total{}; - - vlog.info("RUN %d. Reading frames...", run); - while (av_read_frame(format_ctx, packet) == 0) { - if (packet->stream_index == video_stream_idx) { - if (avcodec_send_packet(codec_ctx, packet) == 0) { - while (avcodec_receive_frame(codec_ctx, frame) == 0) { - // Convert to RGB - sws_scale(sws_ctx, frame->data, frame->linesize, 0, frame->height, - rgb_frame->data, rgb_frame->linesize); - - connection.framebufferUpdateStart(); - connection.setNewFrame(rgb_frame); - using namespace std::chrono; - - auto now = high_resolution_clock::now(); - connection.framebufferUpdateEnd(); - const auto duration = duration_cast(high_resolution_clock::now() - now).count(); - - //vlog.info("Frame took %lu ms", duration); - - timings[frames++] = duration; - total += duration; - } - } - } - av_packet_unref(packet); - } - vlog.info("RUN %d. Done reading frames...", run); - - if (av_seek_frame(format_ctx, video_stream_idx, 0, AVSEEK_FLAG_BACKWARD) < 0) - throw std::runtime_error("Could not seek to start of video"); - - avcodec_flush_buffers(codec_ctx); - - totals[run] = total; - stats[run] = connection.getStats(); - vlog.info("JPEG stats: %u ms", stats[run].jpeg_stats.ms); - vlog.info("WebP stats: %u ms", stats[run].webp_stats.ms); - vlog.info("RUN %d. Bytes sent %lu..", run, stats[run].bytes); - } - - if (frames > 0) - report(totals, timings, stats, results_file); - - avcodec_close(codec_ctx); - - exit(0); } diff --git a/common/rfb/benchmark.h b/common/rfb/benchmark.h index c834dfd..b6fa324 100644 --- a/common/rfb/benchmark.h +++ b/common/rfb/benchmark.h @@ -1,7 +1,5 @@ -/* Copyright 2015 Pierre Ossman for Cendio AB - * Copyright (C) 2015 D. R. Commander. All Rights Reserved. - * Copyright (C) 2025 Kasm Technologies Corp - * +/* Copyright (C) 2025 Kasm Technologies Corp +* * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -20,22 +18,24 @@ #pragma once -#include -#include -#include - #include "CConnection.h" #include "CMsgReader.h" -#include "EncCache.h" -#include "EncodeManager.h" #include "LogWriter.h" -#include "screenTypes.h" -#include "SMsgWriter.h" -#include "ffmpeg.h" + +extern "C" { +#include +} static rfb::LogWriter vlog("Benchmarking"); -namespace rfb { +namespace benchmarking { + using namespace rfb; + + class MockTestConnection : public CConnection { + public: + virtual void setNewFrame(const AVFrame *frame) = 0; + }; + static constexpr rdr::S32 default_encodings[] = { encodingTight, encodingZRLE, @@ -49,226 +49,4 @@ namespace rfb { //pseudoEncodingWEBP //pseudoEncodingQOI }; - - class MockBufferStream final : public rdr::BufferedInStream { - bool fillBuffer(size_t maxSize, bool wait) override { - return true; - } - }; - - class MockStream final : public rdr::OutStream { - public: - MockStream() { - offset = 0; - ptr = buf; - end = buf + sizeof(buf); - } - - private: - void overrun(size_t needed) override { - assert(end >= ptr); - if (needed > static_cast(end - ptr)) - flush(); - } - - public: - size_t length() override { - flush(); - return offset; - } - - void flush() override { - offset += ptr - buf; - ptr = buf; - } - - private: - ptrdiff_t offset; - rdr::U8 buf[8192]{}; - }; - - class MockSConnection final : public SConnection { - public: - MockSConnection() { - setStreams(nullptr, &out); - - setWriter(new SMsgWriter(&cp, &out, &udps)); - } - - ~MockSConnection() override = default; - - void writeUpdate(const UpdateInfo &ui, const PixelBuffer *pb) { - cache.clear(); - - manager.clearEncodingTime(); - if (!ui.is_empty()) { - manager.writeUpdate(ui, pb, nullptr); - } else { - Region region{pb->getRect()}; - manager.writeLosslessRefresh(region, pb, nullptr, 2000); - } - } - - void setDesktopSize(int fb_width, int fb_height, - const ScreenSet &layout) override { - cp.width = fb_width; - cp.height = fb_height; - cp.screenLayout = layout; - - writer()->writeExtendedDesktopSize(reasonServer, 0, cp.width, cp.height, - cp.screenLayout); - } - - void sendStats(const bool toClient) override { - } - - [[nodiscard]] bool canChangeKasmSettings() const override { - return false; - } - - void udpUpgrade(const char *resp) override { - } - - void udpDowngrade(const bool) override { - } - - void subscribeUnixRelay(const char *name) override { - } - - void unixRelay(const char *name, const rdr::U8 *buf, const unsigned len) override { - } - - void handleFrameStats(rdr::U32 all, rdr::U32 render) override { - } - - [[nodiscard]] auto getJpegStats() const { - return manager.jpegstats; - } - - [[nodiscard]] auto getWebPStats() const { - return manager.webpstats; - } - - [[nodiscard]] auto bytes() { return out.length(); } - [[nodiscard]] auto udp_bytes() { return udps.length(); } - - protected: - MockStream out{}; - MockStream udps{}; - - EncCache cache{}; - EncodeManager manager{this, &cache}; - }; - - class MockCConnection final : public CConnection { - public: - explicit MockCConnection(const std::vector& encodings, ManagedPixelBuffer *pb) { - setStreams(&in, nullptr); - - // Need to skip the initial handshake and ServerInit - setState(RFBSTATE_NORMAL); - // That also means that the reader and writer weren't set up - setReader(new rfb::CMsgReader(this, &in)); - auto &pf = pb->getPF(); - CMsgHandler::setPixelFormat(pf); - - MockCConnection::setDesktopSize(pb->width(), pb->height()); - - cp.setPF(pf); - - sc.cp.setPF(pf); - sc.setEncodings(std::size(encodings), encodings.data()); - - setFramebuffer(pb); - } - - void setCursor(int width, int height, const Point &hotspot, const rdr::U8 *data, const bool resizing) override { - } - - ~MockCConnection() override = default; - - struct stats_t { - EncodeManager::codecstats_t jpeg_stats; - EncodeManager::codecstats_t webp_stats; - uint64_t bytes; - uint64_t udp_bytes; - }; - - [[nodiscard]] stats_t getStats() { - return { - sc.getJpegStats(), - sc.getWebPStats(), - sc.bytes(), - sc.udp_bytes() - }; - } - - void setDesktopSize(int w, int h) override { - CConnection::setDesktopSize(w, h); - - if (screen_layout.num_screens()) - screen_layout.remove_screen(0); - - screen_layout.add_screen(Screen(0, 0, 0, w, h, 0)); - } - - void setNewFrame(const AVFrame *frame) { - auto *pb = getFramebuffer(); - const int width = pb->width(); - const int height = pb->height(); - const rfb::Rect rect(0, 0, width, height); - - int dstStride{}; - auto *buffer = pb->getBufferRW(rect, &dstStride); - - const PixelFormat &pf = pb->getPF(); - - // Source data and stride from FFmpeg - const auto *srcData = frame->data[0]; - const int srcStride = frame->linesize[0] / 3; // Convert bytes to pixels - - // Convert from the RGB format to the PixelBuffer's format - pf.bufferFromRGB(buffer, srcData, width, srcStride, height); - - // Commit changes - pb->commitBufferRW(rect); - } - - void framebufferUpdateStart() override { - updates.clear(); - } - - void framebufferUpdateEnd() override { - const PixelBuffer *pb = getFramebuffer(); - - UpdateInfo ui; - const Region clip(pb->getRect()); - - updates.add_changed(pb->getRect()); - - updates.getUpdateInfo(&ui, clip); - sc.writeUpdate(ui, pb); - } - - void dataRect(const Rect &r, int encoding) override { - } - - void setColourMapEntries(int, int, rdr::U16 *) override { - } - - void bell() override { - } - - void serverCutText(const char *, rdr::U32) override { - } - - void serverCutText(const char *str) override { - } - - protected: - MockBufferStream in; - ScreenSet screen_layout; - SimpleUpdateTracker updates; - MockSConnection sc; - }; } diff --git a/common/rfb/ffmpeg.cxx b/common/rfb/ffmpeg.cxx new file mode 100644 index 0000000..2c803d0 --- /dev/null +++ b/common/rfb/ffmpeg.cxx @@ -0,0 +1,210 @@ +/* Copyright (C) 2025 Kasm Technologies Corp +* + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ + +#include "ffmpeg.h" +#include +#include +#include + +FFmpegFrameFeeder::FFmpegFrameFeeder() { + static constexpr std::array paths = { + "/usr/lib/", + "/usr/lib64" + }; + + namespace fs = std::filesystem; + using namespace std::string_literals; + + auto load_lib = [](auto *lib) { + void *handle{}; + for (const auto &dir: paths) { + if (!fs::exists(dir) || !fs::is_directory(dir)) + continue; + + for (const auto &entry: fs::recursive_directory_iterator(dir)) { + if (!entry.is_regular_file()) + continue; + + const std::string filename = entry.path().filename().string(); + if (filename.find(lib) != std::string::npos) { + handle = dlopen(filename.c_str(), RTLD_LAZY); + + break; + } + } + } + + if (!handle) + throw std::runtime_error("Could not open "s + lib); + + return DlHandlerGuard{handle}; + }; + + // libavformat + libavformat = load_lib("libavformat.so"); + auto handle = libavformat.get(); + + avformat_open_input_f = D_LOOKUP_SYM(handle, avformat_open_input); + avformat_find_stream_info_f = D_LOOKUP_SYM(handle, avformat_find_stream_info); + avcodec_find_decoder_f = D_LOOKUP_SYM(handle, avcodec_find_decoder); + avcodec_parameters_to_context_f = D_LOOKUP_SYM(handle, avcodec_parameters_to_context); + av_read_frame_f = D_LOOKUP_SYM(handle, av_read_frame); + av_seek_frame_f = D_LOOKUP_SYM(handle, av_seek_frame); + avformat_close_input_f = D_LOOKUP_SYM(handle, avformat_close_input); + + vlog.info("libavformat.so loaded"); + + // libavutil + libavutil = load_lib("libavutil.so"); + handle = libavutil.get(); + + av_frame_free_f = D_LOOKUP_SYM(handle, av_frame_free); + av_frame_alloc_f = D_LOOKUP_SYM(handle, av_frame_alloc); + av_frame_get_buffer_f = D_LOOKUP_SYM(handle, av_frame_get_buffer); + + vlog.info("libavutil.so loaded"); + + // libswscale + libswscale = load_lib("libswscale.so"); + handle = libswscale.get(); + + sws_freeContext_f = D_LOOKUP_SYM(handle, sws_freeContext); + sws_getContext_f = D_LOOKUP_SYM(handle, sws_getContext); + sws_scale_f = D_LOOKUP_SYM(handle, sws_scale); + + // libavcodec + libavcodec = load_lib("libavcodec.so"); + handle = libavcodec.get(); + + avcodec_open2_f = D_LOOKUP_SYM(handle, avcodec_open2); + avcodec_alloc_context3_f = D_LOOKUP_SYM(handle, avcodec_alloc_context3); + avcodec_send_packet_f = D_LOOKUP_SYM(handle, avcodec_send_packet); + avcodec_receive_frame_f = D_LOOKUP_SYM(handle, avcodec_receive_frame); + av_packet_unref_f = D_LOOKUP_SYM(handle, av_packet_unref); + avcodec_flush_buffers_f = D_LOOKUP_SYM(handle, avcodec_flush_buffers); + avcodec_close_f = D_LOOKUP_SYM(handle, avcodec_close); + av_packet_alloc_f = D_LOOKUP_SYM(handle, av_packet_alloc); + av_packet_free_f = D_LOOKUP_SYM(handle, av_packet_free); +} + +FFmpegFrameFeeder::~FFmpegFrameFeeder() { + avformat_close_input_f(&format_ctx); + avcodec_close_f(codec_ctx); + avcodec_free_context_f(&codec_ctx); +} + +void FFmpegFrameFeeder::open(const std::string_view path) { + if (avformat_open_input_f(&format_ctx, path.data(), nullptr, nullptr) < 0) + throw std::runtime_error("Could not open video file"); + + // Find stream info + if (avformat_find_stream_info_f(format_ctx, nullptr) < 0) + throw std::runtime_error("Could not find stream info"); + + // Find video stream + for (uint32_t i = 0; i < format_ctx->nb_streams; ++i) { + if (format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + video_stream_idx = static_cast(i); + break; + } + } + + if (video_stream_idx == -1) + throw std::runtime_error("No video stream found"); + + // Get codec parameters and decoder + const auto *codec_parameters = format_ctx->streams[video_stream_idx]->codecpar; + const auto *codec = avcodec_find_decoder_f(codec_parameters->codec_id); + if (!codec) + throw std::runtime_error("Codec not found"); + + codec_ctx = avcodec_alloc_context3_f(codec); + if (!codec_ctx || avcodec_parameters_to_context_f(codec_ctx, codec_parameters) < 0) + throw std::runtime_error("Failed to set up codec context"); + + if (avcodec_open2_f(codec_ctx, codec, nullptr) < 0) + throw std::runtime_error("Could not open codec"); +} + +FFmpegFrameFeeder::play_stats_t FFmpegFrameFeeder::play(benchmarking::MockTestConnection *connection) const { + // Allocate frame and packet + const FrameGuard frame{av_frame_alloc_f()}; + const PacketGuard packet{av_packet_alloc_f()}; + + if (!frame || !packet) + throw std::runtime_error("Could not allocate frame or packet"); + + // Scaling context to convert to RGB24 + SwsContext *sws_ctx = sws_getContext_f( + codec_ctx->width, codec_ctx->height, codec_ctx->pix_fmt, + codec_ctx->width, codec_ctx->height, AV_PIX_FMT_RGB24, + SWS_BILINEAR, nullptr, nullptr, nullptr + ); + if (!sws_ctx) + throw std::runtime_error("Could not create scaling context"); + + const std::unique_ptr sws_ctx_guard{sws_ctx, sws_freeContext_f}; + + const FrameGuard rgb_frame{av_frame_alloc_f()}; + if (!rgb_frame) + throw std::runtime_error("Could not allocate frame"); + + rgb_frame->format = AV_PIX_FMT_RGB24; + rgb_frame->width = codec_ctx->width; + rgb_frame->height = codec_ctx->height; + + if (av_frame_get_buffer_f(rgb_frame.get(), 0) != 0) + throw std::runtime_error("Could not allocate frame data"); + + play_stats_t stats{}; + const auto total_frame_count = get_total_frame_count(); + stats.timings.reserve(total_frame_count > 0 ? total_frame_count : 2048); + + while (av_read_frame_f(format_ctx, packet.get()) == 0) { + if (packet->stream_index == video_stream_idx) { + if (avcodec_send_packet_f(codec_ctx, packet.get()) == 0) { + while (avcodec_receive_frame_f(codec_ctx, frame.get()) == 0) { + // Convert to RGB + sws_scale_f(sws_ctx_guard.get(), frame->data, frame->linesize, 0, + frame->height, + rgb_frame->data, rgb_frame->linesize); + + connection->framebufferUpdateStart(); + connection->setNewFrame(rgb_frame.get()); + using namespace std::chrono; + + auto now = high_resolution_clock::now(); + connection->framebufferUpdateEnd(); + const auto duration = duration_cast(high_resolution_clock::now() - now).count(); + + //vlog.info("Frame took %lu ms", duration); + stats.total += duration; + stats.timings.push_back(duration); + } + } + } + av_packet_unref_f(packet.get()); + } + + if (av_seek_frame_f(format_ctx, video_stream_idx, 0, AVSEEK_FLAG_BACKWARD) < 0) + throw std::runtime_error("Could not seek to start of video"); + + avcodec_flush_buffers_f(codec_ctx); + + return stats; +} diff --git a/common/rfb/ffmpeg.h b/common/rfb/ffmpeg.h index fa3539c..61edbf2 100644 --- a/common/rfb/ffmpeg.h +++ b/common/rfb/ffmpeg.h @@ -18,7 +18,10 @@ #pragma once +#include #include +#include +#include "LogWriter.h" extern "C" { #include @@ -26,38 +29,140 @@ extern "C" { #include } -struct AVFormatContextDeleter { - void operator()(AVFormatContext *ctx) const { - avformat_close_input(&ctx); - } -}; +#include "benchmark.h" -struct AVCodecContextDeleter { - void operator()(AVCodecContext *ctx) const { - avcodec_free_context(&ctx); - } -}; +#define STR_HELPER(x) #x +#define STR(x) STR_HELPER(x) +#define CONCAT_STR(a, b) a b -struct AVFrameDeleter { - void operator()(AVFrame *frame) const { - av_frame_free(&frame); - } -}; +#define D_LOOKUP_SYM(handle, name) \ + [](auto handle, auto *sym_name) -> auto { \ + auto *sym = reinterpret_cast(dlsym(handle, sym_name)); \ + if (!sym) \ + throw std::runtime_error("Failed to load symbol "s + sym_name); \ + return sym; \ + }(handle, STR(name)) -struct SwsContextDeleter { - void operator()(SwsContext *ctx) const { - sws_freeContext(ctx); - } -}; +#define DEFINE_GUARD(name, type, deleter) \ + using name##Guard = std::unique_ptr; -struct PacketDeleter { - void operator()(AVPacket *packet) const { - av_packet_free(&packet); - } -}; +//using SwsContextGuard = std::unique_ptr; -using FormatCtxGuard = std::unique_ptr; -using CodecCtxGuard = std::unique_ptr; -using FrameGuard = std::unique_ptr; -using SwsContextGuard = std::unique_ptr; -using PacketGuard = std::unique_ptr; +class FFmpegFrameFeeder final { + // libavformat + using avformat_close_input_func = void(*)(AVFormatContext **); + using avformat_open_input_func = int(*)(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, + AVDictionary **options); + using avformat_find_stream_info_func = int (*)(AVFormatContext *ic, AVDictionary **options); + using av_read_frame_func = int (*)(AVFormatContext *s, AVPacket *pkt); + using av_seek_frame_func = int (*)(AVFormatContext *s, int stream_index, int64_t timestamp, int flags); + + // libavutil + using av_frame_free_func = void (*)(AVFrame **); + using av_frame_alloc_func = AVFrame *(*)(); + using av_frame_get_buffer_func = int (*)(AVFrame *frame, int align); + + // libswscale + using sws_freeContext_func = void (*)(SwsContext *); + using sws_getContext_func = SwsContext * (*)(int srcW, int srcH, AVPixelFormat srcFormat, int dstW, int dstH, + AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, + SwsFilter *dstFilter, const double *param); + + using sws_scale_func = int(*)(SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, + int srcSliceH, uint8_t *const dst[], const int dstStride[]); + + // libavcodec + using avcodec_free_context_func = void (*)(AVCodecContext **); + using av_packet_free_func = void (*)(AVPacket **); + using avcodec_find_decoder_func = const AVCodec * (*)(AVCodecID id); + using avcodec_alloc_context3_func = AVCodecContext* (*)(const AVCodec *codec); + using avcodec_parameters_to_context_func = int (*)(AVCodecContext *codec, const AVCodecParameters *par); + using avcodec_open2_func = int (*)(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options); + using av_packet_alloc_func = AVPacket *(*)(); + using avcodec_send_packet_func = int(*)(AVCodecContext *avctx, const AVPacket *avpkt); + using avcodec_receive_frame_func = int(*)(AVCodecContext *avctx, AVFrame *frame); + using av_packet_unref_func = void (*)(AVPacket *pkt); + using avcodec_flush_buffers_func = void (*)(AVCodecContext *avctx); + using avcodec_close_func = int (*)(AVCodecContext *avctx); + + struct DlHandler { + void operator()(void *handle) const { + dlclose(handle); + } + }; + + using DlHandlerGuard = std::unique_ptr; + + // libavformat + avformat_close_input_func avformat_close_input_f{}; + avformat_open_input_func avformat_open_input_f{}; + avformat_find_stream_info_func avformat_find_stream_info_f{}; + av_read_frame_func av_read_frame_f{}; + av_seek_frame_func av_seek_frame_f{}; + + // libavutil + static inline av_frame_free_func av_frame_free_f{}; + av_frame_alloc_func av_frame_alloc_f{}; + av_frame_get_buffer_func av_frame_get_buffer_f{}; + + // libswscale + sws_freeContext_func sws_freeContext_f{}; + sws_getContext_func sws_getContext_f{}; + sws_scale_func sws_scale_f{}; + + // libavcodec + avcodec_free_context_func avcodec_free_context_f{}; + static inline av_packet_free_func av_packet_free_f{}; + avcodec_find_decoder_func avcodec_find_decoder_f{}; + avcodec_alloc_context3_func avcodec_alloc_context3_f{}; + avcodec_parameters_to_context_func avcodec_parameters_to_context_f{}; + avcodec_open2_func avcodec_open2_f{}; + av_packet_alloc_func av_packet_alloc_f{}; + avcodec_send_packet_func avcodec_send_packet_f{}; + avcodec_receive_frame_func avcodec_receive_frame_f{}; + av_packet_unref_func av_packet_unref_f{}; + avcodec_flush_buffers_func avcodec_flush_buffers_f{}; + avcodec_close_func avcodec_close_f{}; + + rfb::LogWriter vlog{"FFmpeg"}; + + DEFINE_GUARD(Frame, AVFrame, av_frame_free) + DEFINE_GUARD(Packet, AVPacket, av_packet_free) + + AVFormatContext *format_ctx{}; + AVCodecContext *codec_ctx{}; + int video_stream_idx{-1}; + + DlHandlerGuard libavformat{}; + DlHandlerGuard libavutil{}; + DlHandlerGuard libswscale{}; + DlHandlerGuard libavcodec{}; + +public: + FFmpegFrameFeeder(); + + ~FFmpegFrameFeeder(); + + void open(std::string_view path); + + [[nodiscard]] int64_t get_total_frame_count() const { + return format_ctx->streams[video_stream_idx]->nb_frames; + } + + struct frame_dimensions_t { + int width{}; + int height{}; + }; + + [[nodiscard]] frame_dimensions_t get_frame_dimensions() const { + return {codec_ctx->width, codec_ctx->height}; + } + + struct play_stats_t { + uint64_t frames{}; + uint64_t total{}; + std::vector timings; + }; + + play_stats_t play(benchmarking::MockTestConnection *connection) const; +}; diff --git a/unix/xserver/hw/vnc/vncExtInit.cc b/unix/xserver/hw/vnc/vncExtInit.cc index c8ea188..8c74aa8 100644 --- a/unix/xserver/hw/vnc/vncExtInit.cc +++ b/unix/xserver/hw/vnc/vncExtInit.cc @@ -184,7 +184,7 @@ static void parseClipTypes() vlog.debug("Adding DLP binary mime type %s", m.mime); } - vlog.debug("Total %u binary mime types", dlp_mimetypes.size()); + vlog.debug("Total %lu binary mime types", dlp_mimetypes.size()); free(origstr); } From df650b7d0c216cc78199743bcd334775eacc337d Mon Sep 17 00:00:00 2001 From: El Date: Thu, 1 May 2025 16:56:57 +0500 Subject: [PATCH 160/167] KASM-6984 Add WebP for benchmarking when value is not default --- common/rfb/benchmark.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index 4218d91..0812f7e 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -358,12 +358,12 @@ void benchmark(std::string_view path, const std::string_view results_file) { frame_feeder.open(path); static const rfb::PixelFormat pf{32, 24, false, true, 0xFF, 0xFF, 0xFF, 0, 8, 16}; - const std::vector encodings{ + std::vector encodings{ std::begin(benchmarking::default_encodings), std::end(benchmarking::default_encodings) }; - // if (rfb::Server::WebPEnabled) - // encodings.push_back(rfb::pseudoEncodingWEBP); + if (rfb::Server::webpEncodingTime != 30) + encodings.push_back(rfb::pseudoEncodingWEBP); constexpr auto runs = 20; std::vector totals(runs, 0); From dd12dcd2b74ccd881759708905ade028c51797dd Mon Sep 17 00:00:00 2001 From: El Date: Thu, 1 May 2025 17:27:37 +0500 Subject: [PATCH 161/167] KASM-6984 Reverted changes --- builder/dockerfile.debian_bookworm.deb.build | 2 +- builder/dockerfile.debian_bullseye.deb.build | 2 +- builder/dockerfile.kali_kali-rolling.deb.build | 2 +- builder/dockerfile.ubuntu_focal.deb.build | 2 +- builder/dockerfile.ubuntu_jammy.deb.build | 2 +- builder/dockerfile.ubuntu_noble.deb.build | 2 +- oracle/kasmvncserver.spec | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/builder/dockerfile.debian_bookworm.deb.build b/builder/dockerfile.debian_bookworm.deb.build index 7e38d57..2e61fbb 100644 --- a/builder/dockerfile.debian_bookworm.deb.build +++ b/builder/dockerfile.debian_bookworm.deb.build @@ -3,7 +3,7 @@ FROM debian:bookworm ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs libavformat-dev libswscale-dev + apt-get -y install vim build-essential devscripts equivs # Install build-deps for the package. COPY ./debian/control /tmp diff --git a/builder/dockerfile.debian_bullseye.deb.build b/builder/dockerfile.debian_bullseye.deb.build index e8c0ae1..51bde4f 100644 --- a/builder/dockerfile.debian_bullseye.deb.build +++ b/builder/dockerfile.debian_bullseye.deb.build @@ -3,7 +3,7 @@ FROM debian:bullseye ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs libavformat-dev libswscale-dev + apt-get -y install vim build-essential devscripts equivs # Install build-deps for the package. COPY ./debian/control /tmp diff --git a/builder/dockerfile.kali_kali-rolling.deb.build b/builder/dockerfile.kali_kali-rolling.deb.build index 3683530..6d0ed1b 100644 --- a/builder/dockerfile.kali_kali-rolling.deb.build +++ b/builder/dockerfile.kali_kali-rolling.deb.build @@ -3,7 +3,7 @@ FROM kalilinux/kali-rolling:latest ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs libavformat-dev libswscale-dev + apt-get -y install vim build-essential devscripts equivs # Install build-deps for the package. COPY ./debian/control /tmp diff --git a/builder/dockerfile.ubuntu_focal.deb.build b/builder/dockerfile.ubuntu_focal.deb.build index 5528d2c..ffe6402 100644 --- a/builder/dockerfile.ubuntu_focal.deb.build +++ b/builder/dockerfile.ubuntu_focal.deb.build @@ -3,7 +3,7 @@ FROM ubuntu:focal ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs libtbb-dev libavformat-dev libswscale-dev + apt-get -y install vim build-essential devscripts equivs libtbb-dev # Install build-deps for the package. COPY ./debian/control /tmp diff --git a/builder/dockerfile.ubuntu_jammy.deb.build b/builder/dockerfile.ubuntu_jammy.deb.build index ce9d84c..31dee99 100644 --- a/builder/dockerfile.ubuntu_jammy.deb.build +++ b/builder/dockerfile.ubuntu_jammy.deb.build @@ -3,7 +3,7 @@ FROM ubuntu:jammy ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs libavformat-dev libswscale-dev + apt-get -y install vim build-essential devscripts equivs # Install build-deps for the package. COPY ./debian/control /tmp diff --git a/builder/dockerfile.ubuntu_noble.deb.build b/builder/dockerfile.ubuntu_noble.deb.build index 982de54..6a56b24 100644 --- a/builder/dockerfile.ubuntu_noble.deb.build +++ b/builder/dockerfile.ubuntu_noble.deb.build @@ -3,7 +3,7 @@ FROM ubuntu:noble ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install vim build-essential devscripts equivs libavformat-dev libswscale-dev + apt-get -y install vim build-essential devscripts equivs # Install build-deps for the package. COPY ./debian/control /tmp diff --git a/oracle/kasmvncserver.spec b/oracle/kasmvncserver.spec index e08897a..85751bd 100644 --- a/oracle/kasmvncserver.spec +++ b/oracle/kasmvncserver.spec @@ -7,7 +7,7 @@ License: GPLv2+ URL: https://github.com/kasmtech/KasmVNC BuildRequires: rsync -Requires: xorg-x11-xauth, xorg-x11-xkb-utils, xkeyboard-config, xorg-x11-server-utils, openssl, perl, perl-Switch, perl-YAML-Tiny, perl-Hash-Merge-Simple, perl-Scalar-List-Utils, perl-List-MoreUtils, perl-Try-Tiny, perl-DateTime-TimeZone, hostname, mesa-libgbm, libxshmfence, ffmpeg-libs +Requires: xorg-x11-xauth, xorg-x11-xkb-utils, xkeyboard-config, xorg-x11-server-utils, openssl, perl, perl-Switch, perl-YAML-Tiny, perl-Hash-Merge-Simple, perl-Scalar-List-Utils, perl-List-MoreUtils, perl-Try-Tiny, perl-DateTime-TimeZone, hostname, mesa-libgbm, libxshmfence Conflicts: tigervnc-server, tigervnc-server-minimal %description From af1a615dd15d58df1de326fc0444da5c1bf193ec Mon Sep 17 00:00:00 2001 From: El Date: Thu, 1 May 2025 17:45:14 +0500 Subject: [PATCH 162/167] KASM-6984 Reverted added line --- builder/dockerfile.opensuse_15.build | 1 - 1 file changed, 1 deletion(-) diff --git a/builder/dockerfile.opensuse_15.build b/builder/dockerfile.opensuse_15.build index a385424..63d9358 100644 --- a/builder/dockerfile.opensuse_15.build +++ b/builder/dockerfile.opensuse_15.build @@ -48,7 +48,6 @@ RUN zypper install -ny \ xorg-x11-server-sdk \ xorg-x11-util-devel \ zlib-devel -#RUN zypper install -ny libavformat-devel libswscale-devel RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 140 \ --slave /usr/bin/g++ g++ /usr/bin/g++-14 \ From ee43b75f387200b80249d0823659327cea03fe0f Mon Sep 17 00:00:00 2001 From: El Date: Fri, 2 May 2025 16:09:37 +0500 Subject: [PATCH 163/167] KASM-6984 Update benchmark specs and CI to include JPEG and WebP results --- .gitlab-ci.yml | 3 ++- spec/vncserver_adv_benchmarking_spec.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ad6e84f..678b7fc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -535,7 +535,8 @@ test: reports: junit: - SelfBench.xml - - Benchmark.xml + - JpegBenchmark.xml + - WebPBenchmark.xml script: - bash builder/test-vncserver diff --git a/spec/vncserver_adv_benchmarking_spec.py b/spec/vncserver_adv_benchmarking_spec.py index 8e4b10f..3ddc0c0 100644 --- a/spec/vncserver_adv_benchmarking_spec.py +++ b/spec/vncserver_adv_benchmarking_spec.py @@ -9,7 +9,14 @@ with description("Benchmarking"): kill_xvnc() with it("runs benchmarks"): run_cmd("wget --no-check-certificate https://kasmweb-build-artifacts.s3.us-east-1.amazonaws.com/kasmvnc/static/127072-737747495_small.mp4 -O /tmp/video.mp4") - completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -Benchmark /tmp/video.mp4 -VideoArea 100") - command = '''sed -i "s/KasmVNC/$(grep -E '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"') $(grep -E '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2 | tr -d '"')/g" Benchmark.xml''' - run_cmd(command) + completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -Benchmark /tmp/video.mp4 -VideoArea 100 -BenchmarkResults JpegBenchmark.xml") expect(completed_process.returncode).to(equal(0)) + + run_cmd('''sed -i "s/KasmVNC/$(grep -E '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"') $(grep -E '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2 | tr -d '"')/g" JpegBenchmark.xml''') + run_cmd("sed -i 's/testcase name=\"/testcase name=\"JPEG: /g' JpegBenchmark.xml") + + completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -Benchmark /tmp/video.mp4 -VideoArea 100 -BenchmarkResults WebPBenchmark.xml") + expect(completed_process.returncode).to(equal(0)) + + run_cmd('''sed -i "s/KasmVNC/$(grep -E '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"') $(grep -E '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2 | tr -d '"')/g" WebPBenchmark.xml''') + run_cmd("sed -i 's/testcase name=\"/testcase name=\"WebP: /g' WebPBenchmark.xml") From 7c4250666a535f74d2922b9d63427a1af5806bfa Mon Sep 17 00:00:00 2001 From: El Date: Fri, 2 May 2025 20:10:42 +0500 Subject: [PATCH 164/167] KASM-6984 Revert changes --- .gitlab-ci.yml | 3 +-- common/rfb/benchmark.cxx | 3 --- common/rfb/benchmark.h | 3 +-- spec/vncserver_adv_benchmarking_spec.py | 13 +++---------- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 678b7fc..ad6e84f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -535,8 +535,7 @@ test: reports: junit: - SelfBench.xml - - JpegBenchmark.xml - - WebPBenchmark.xml + - Benchmark.xml script: - bash builder/test-vncserver diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index 0812f7e..21b1bd2 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -362,9 +362,6 @@ void benchmark(std::string_view path, const std::string_view results_file) { std::begin(benchmarking::default_encodings), std::end(benchmarking::default_encodings) }; - if (rfb::Server::webpEncodingTime != 30) - encodings.push_back(rfb::pseudoEncodingWEBP); - constexpr auto runs = 20; std::vector totals(runs, 0); std::vector stats(runs); diff --git a/common/rfb/benchmark.h b/common/rfb/benchmark.h index b6fa324..18659f6 100644 --- a/common/rfb/benchmark.h +++ b/common/rfb/benchmark.h @@ -37,6 +37,7 @@ namespace benchmarking { }; static constexpr rdr::S32 default_encodings[] = { + pseudoEncodingWEBP, encodingTight, encodingZRLE, encodingHextile, @@ -46,7 +47,5 @@ namespace benchmarking { pseudoEncodingQualityLevel9, pseudoEncodingFineQualityLevel100, pseudoEncodingSubsamp16X - //pseudoEncodingWEBP - //pseudoEncodingQOI }; } diff --git a/spec/vncserver_adv_benchmarking_spec.py b/spec/vncserver_adv_benchmarking_spec.py index 3ddc0c0..8e4b10f 100644 --- a/spec/vncserver_adv_benchmarking_spec.py +++ b/spec/vncserver_adv_benchmarking_spec.py @@ -9,14 +9,7 @@ with description("Benchmarking"): kill_xvnc() with it("runs benchmarks"): run_cmd("wget --no-check-certificate https://kasmweb-build-artifacts.s3.us-east-1.amazonaws.com/kasmvnc/static/127072-737747495_small.mp4 -O /tmp/video.mp4") - completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -Benchmark /tmp/video.mp4 -VideoArea 100 -BenchmarkResults JpegBenchmark.xml") + completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -Benchmark /tmp/video.mp4 -VideoArea 100") + command = '''sed -i "s/KasmVNC/$(grep -E '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"') $(grep -E '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2 | tr -d '"')/g" Benchmark.xml''' + run_cmd(command) expect(completed_process.returncode).to(equal(0)) - - run_cmd('''sed -i "s/KasmVNC/$(grep -E '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"') $(grep -E '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2 | tr -d '"')/g" JpegBenchmark.xml''') - run_cmd("sed -i 's/testcase name=\"/testcase name=\"JPEG: /g' JpegBenchmark.xml") - - completed_process = run_cmd("Xvnc -interface 0.0.0.0 :1 -Benchmark /tmp/video.mp4 -VideoArea 100 -BenchmarkResults WebPBenchmark.xml") - expect(completed_process.returncode).to(equal(0)) - - run_cmd('''sed -i "s/KasmVNC/$(grep -E '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"') $(grep -E '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2 | tr -d '"')/g" WebPBenchmark.xml''') - run_cmd("sed -i 's/testcase name=\"/testcase name=\"WebP: /g' WebPBenchmark.xml") From 5fba51986b0432d7e565e372a0dbcc541500d8a9 Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 2 May 2025 17:52:20 +0000 Subject: [PATCH 165/167] Use pseudoEncodings that match client default settings --- common/rfb/benchmark.cxx | 2 +- common/rfb/benchmark.h | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/common/rfb/benchmark.cxx b/common/rfb/benchmark.cxx index 21b1bd2..c837c0f 100644 --- a/common/rfb/benchmark.cxx +++ b/common/rfb/benchmark.cxx @@ -113,7 +113,7 @@ namespace benchmarking { } [[nodiscard]] bool canChangeKasmSettings() const override { - return false; + return true; } void udpUpgrade(const char *resp) override { diff --git a/common/rfb/benchmark.h b/common/rfb/benchmark.h index 18659f6..1feaa3e 100644 --- a/common/rfb/benchmark.h +++ b/common/rfb/benchmark.h @@ -37,15 +37,31 @@ namespace benchmarking { }; static constexpr rdr::S32 default_encodings[] = { - pseudoEncodingWEBP, + encodingTight, - encodingZRLE, encodingHextile, encodingRRE, encodingRaw, - pseudoEncodingCompressLevel9, - pseudoEncodingQualityLevel9, - pseudoEncodingFineQualityLevel100, - pseudoEncodingSubsamp16X + pseudoEncodingQualityLevel0 + 6, + pseudoEncodingCompressLevel0 + 2, + pseudoEncodingDesktopSize, + pseudoEncodingLastRect, + pseudoEncodingQEMUKeyEvent, + pseudoEncodingExtendedDesktopSize, + pseudoEncodingFence, + pseudoEncodingContinuousUpdates, + pseudoEncodingDesktopName, + pseudoEncodingExtendedClipboard, + pseudoEncodingWEBP, + pseudoEncodingJpegVideoQualityLevel0 + 7, + pseudoEncodingWebpVideoQualityLevel0 + 7, + pseudoEncodingTreatLosslessLevel0 + 7, + pseudoEncodingDynamicQualityMinLevel0 + 4, + pseudoEncodingDynamicQualityMaxLevel0 + 9, + pseudoEncodingVideoAreaLevel1 - 1 + 65, + pseudoEncodingVideoTimeLevel0 + 5, + pseudoEncodingVideoOutTimeLevel1 - 1 + 3, + pseudoEncodingFrameRateLevel10 - 10 + 60, + pseudoEncodingMaxVideoResolution }; } From f13a4c198c263e1cd53e685e50f774d1977ebea3 Mon Sep 17 00:00:00 2001 From: matt Date: Sat, 3 May 2025 10:44:36 +0000 Subject: [PATCH 166/167] clarify readme --- BUILDING.txt | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/BUILDING.txt b/BUILDING.txt index 34c6cdf..4cd1a8e 100644 --- a/BUILDING.txt +++ b/BUILDING.txt @@ -78,7 +78,7 @@ Building the KasmVNC Server using Docker git submodule init git submodule update --remote --merge sudo docker build -t kasmvnc:dev -f builder/dockerfile.ubuntu_jammy.dev . -sudo docker run -it -v ./:/src -p 6901:6901 kasmvnc:dev +sudo docker run -it --rm -v ./:/src -p 6901:6901 -p 8443:8443 --name kasmvnc_dev kasmvnc:dev ``` Now from inside the container. @@ -89,9 +89,9 @@ cd kasmweb npm install npm run build # <-- only run this on subsequent changes to front-end code cd .. -# build dependencies -sudo builder/scripts/build-webp -sudo builder/scripts/build-libjpeg-turbo +# build dependencies, this is optional as they are pre-built in the docker image. Only rebuild if you made version changes and need to test. +# sudo builder/scripts/build-webp +# sudo builder/scripts/build-libjpeg-turbo # Build KasmVNC builder/build.sh ``` @@ -108,12 +108,7 @@ Now open a browser and navigate to your dev VM on port 6901. Running noVNC from source ------------------------- If you need to debug or make changes to the UI code, use the following procedures to use npm to serve the web code. The code will automatically rebuild when changes are made and the code will not be packaged. -These steps assume you have already built the docker image covered in the previous section named `kasmvnc:dev`. - -```bash -# run an instance of the dev container, expose an additional port -sudo docker run -it -v ./:/src -p 6901:6901 -p 8443:8443 --name kasmvnc_dev kasmvnc:dev -``` +These steps assume you are inside the kasmvnc:dev container started in the above steps. Now from inside the container. **This assumes KasmVNC is already built, follow steps above if you need to build KasmVNC** @@ -124,7 +119,7 @@ Now from inside the container. **This assumes KasmVNC is already built, follow s sudo nginx cd kasmweb -npm install +npm install # only needs done first time npm run serve # <-- Needs to run in foreground ``` From 0244c47d7a462c713ebdf35d40b303a828735676 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Sat, 10 May 2025 09:52:34 +0000 Subject: [PATCH 167/167] KASM-7052 Add test-barebones --- .ci/upload.sh | 76 ++- .gitignore | 3 + .gitlab-ci.yml | 618 ++---------------- builder/build-package | 9 +- builder/common.sh | 23 + builder/dockerfile.alpine.barebones.apk.test | 24 + .../dockerfile.alpine_318.barebones.apk.test | 1 + .../dockerfile.alpine_319.barebones.apk.test | 1 + .../dockerfile.alpine_320.barebones.apk.test | 1 + .../dockerfile.alpine_321.barebones.apk.test | 1 + builder/dockerfile.debian.barebones.deb.test | 22 + ...kerfile.debian_bookworm.barebones.deb.test | 1 + ...kerfile.debian_bullseye.barebones.deb.test | 1 + ...dockerfile.fedora_forty.barebones.rpm.test | 25 + ...kerfile.fedora_fortyone.barebones.rpm.test | 25 + ...rfile.kali_kali-rolling.barebones.deb.test | 1 + .../dockerfile.opensuse_15.barebones.rpm.test | 5 +- .../dockerfile.oracle_8.barebones.rpm.test | 12 +- .../dockerfile.oracle_9.barebones.rpm.test | 4 +- ...dockerfile.ubuntu_focal.barebones.deb.test | 21 +- ...dockerfile.ubuntu_jammy.barebones.deb.test | 1 + ...dockerfile.ubuntu_noble.barebones.deb.test | 1 + builder/process_test_options.sh | 6 +- builder/scripts/install_kasmvncserver_package | 28 +- builder/startup/vnc_startup_barebones.sh | 5 + builder/test-apk-barebones | 30 + builder/test-barebones | 42 ++ builder/test-deb-barebones | 19 +- builder/test-rpm-barebones | 17 +- 29 files changed, 404 insertions(+), 619 deletions(-) create mode 100644 builder/dockerfile.alpine.barebones.apk.test create mode 120000 builder/dockerfile.alpine_318.barebones.apk.test create mode 120000 builder/dockerfile.alpine_319.barebones.apk.test create mode 120000 builder/dockerfile.alpine_320.barebones.apk.test create mode 120000 builder/dockerfile.alpine_321.barebones.apk.test create mode 100644 builder/dockerfile.debian.barebones.deb.test create mode 120000 builder/dockerfile.debian_bookworm.barebones.deb.test create mode 120000 builder/dockerfile.debian_bullseye.barebones.deb.test create mode 100644 builder/dockerfile.fedora_forty.barebones.rpm.test create mode 100644 builder/dockerfile.fedora_fortyone.barebones.rpm.test create mode 120000 builder/dockerfile.kali_kali-rolling.barebones.deb.test mode change 100644 => 120000 builder/dockerfile.ubuntu_focal.barebones.deb.test create mode 120000 builder/dockerfile.ubuntu_jammy.barebones.deb.test create mode 120000 builder/dockerfile.ubuntu_noble.barebones.deb.test create mode 100755 builder/test-apk-barebones create mode 100755 builder/test-barebones diff --git a/.ci/upload.sh b/.ci/upload.sh index cc51e50..7541b84 100644 --- a/.ci/upload.sh +++ b/.ci/upload.sh @@ -61,24 +61,80 @@ function prepare_upload_filename() { fi }; +list_files_in_directory() { + local dir="$1" + find "$1" -mindepth 1 +} + +upload_directory_to_s3() { + local dir_to_upload="$1" + local s3_directory="$2"; + local s3_bucket="$3"; + + for file_to_upload in $(list_files_in_directory "$dir_to_upload"); do + upload_to_s3 "$file_to_upload" "$s3_directory/$file_to_upload" "$s3_bucket" + done +} + +prepare_functional_tests_source_and_cd_into_it() { + git clone https://gitlab-ci-token:$CI_JOB_TOKEN@gitlab.com/kasm-technologies/internal/kasmvnc-functional-tests.git + cd kasmvnc-functional-tests + mkdir output && chown 1000:1000 output + mkdir report && chown 1000:1000 report +} + +upload_report_to_s3() { + s3_tests_directory="kasmvnc/${CI_COMMIT_SHA}/tests" + upload_directory_to_s3 report "$s3_tests_directory" "$S3_BUCKET" + aws s3 cp report/index.html "s3://${S3_BUCKET}/${s3_tests_directory}/report/index.html" --metadata-directive REPLACE --content-type "text/html" +} + +put_report_into_ci_pipeline() { + report_name="Functional%20test%20report" + report_url="https://${S3_BUCKET}.s3.amazonaws.com/${s3_tests_directory}/report/index.html" + curl --request POST --header "PRIVATE-TOKEN:${GITLAB_API_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/statuses/${CI_COMMIT_SHA}?state=success&name=${report_name}&target_url=${report_url}" +} + +prepare_kasmvnc_built_packages_to_replace_workspaces_image_packages() { + cp -r ../output/jammy output/ +} + +prepare_to_run_functional_tests() { + install_packages_needed_for_functional_tests + prepare_functional_tests_source_and_cd_into_it + prepare_s3_uploader + prepare_kasmvnc_built_packages_to_replace_workspaces_image_packages +} + +install_packages_needed_for_functional_tests() { + export DEBIAN_FRONTEND=noninteractive + apt-get update && apt-get install -y git tree curl docker.io awscli + apt-get install -y ruby3.1 wget + apt-get install -y python3 python3-pip python3-boto3 curl pkg-config libxmlsec1-dev +} + function upload_to_s3() { - local package="$1"; - local upload_filename="$2"; + local file_to_upload="$1"; + local s3_url_for_file="$2"; local s3_bucket="$3"; # Transfer to S3 - python3 amazon-s3-bitbucket-pipelines-python/s3_upload.py "${s3_bucket}" "$package" "${upload_filename}"; + python3 amazon-s3-bitbucket-pipelines-python/s3_upload.py "$s3_bucket" "$file_to_upload" "$s3_url_for_file"; # Use the Gitlab API to tell Gitlab where the artifact was stored - export S3_URL="https://${s3_bucket}.s3.amazonaws.com/${upload_filename}"; + export S3_URL="https://${s3_bucket}.s3.amazonaws.com/${s3_url_for_file}"; }; +function prepare_s3_uploader() { + git clone https://bitbucket.org/awslabs/amazon-s3-bitbucket-pipelines-python.git +} + function prepare_to_run_scripts_and_s3_uploads() { - export DEBIAN_FRONTEND=noninteractive; - apt-get update; - apt-get install -y ruby2.7 git wget; - apt-get install -y python3 python3-pip python3-boto3 curl pkg-config libxmlsec1-dev; - git clone https://bitbucket.org/awslabs/amazon-s3-bitbucket-pipelines-python.git; -}; + export DEBIAN_FRONTEND=noninteractive + apt-get update + apt-get install -y ruby2.7 git wget + apt-get install -y python3 python3-pip python3-boto3 curl pkg-config libxmlsec1-dev + prepare_s3_uploader +} detect_release_branch() { if echo $CI_COMMIT_REF_NAME | grep -Pq '^release/([\d.]+)$'; then diff --git a/.gitignore b/.gitignore index 35ea059..3f92e8f 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,9 @@ debian/kasmvncserver/ .pc .vscode/ +# --run-test artifacts +run_test/ + alpine/.abuild/kasmvnc_signing_key.rsa alpine/.abuild/kasmvnc_signing_key.rsa.pub alpine/packages/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ad6e84f..ebf0947 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,6 +22,8 @@ workflow: stages: - www - build + - functional_test + - run_test - test - upload @@ -42,6 +44,24 @@ default: tags: - oci-fixed-amd +functional_test: + stage: functional_test + image: debian:bookworm + tags: + - oci-fixed-amd + before_script: + - . .ci/upload.sh + script: + - prepare_to_run_functional_tests + - ./functional-test + - upload_report_to_s3 + - put_report_into_ci_pipeline + dependencies: + - build_amd64 + artifacts: + paths: + - kasmvnc-functional-tests/output/ + build_www: stage: www allow_failure: false @@ -67,7 +87,7 @@ build_www: paths: - output/ -build_ubuntu_focal: +build_amd64: stage: build allow_failure: true tags: @@ -78,15 +98,18 @@ build_ubuntu_focal: after_script: - *prepare_artfacts script: - - bash builder/build-package ubuntu focal; + - bash builder/build-package $DISTRO; only: variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ "$DISTRO" artifacts: paths: - output/ + parallel: + matrix: + - DISTRO: [ 'ubuntu focal', 'ubuntu jammy', 'ubuntu noble', 'debian bullseye', 'debian bookworm', 'kali kali-rolling', 'oracle 8', 'oracle 9', 'opensuse 15', 'fedora forty', 'fedora fortyone', 'alpine 318', 'alpine 319', 'alpine 320', 'alpine 321' ] -build_ubuntu_focal_arm: +build_arm64: stage: build allow_failure: true tags: @@ -97,435 +120,60 @@ build_ubuntu_focal_arm: after_script: - *prepare_artfacts script: - - bash builder/build-package ubuntu focal; + - bash builder/build-package $DISTRO; only: variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ "$DISTRO" artifacts: paths: - output/ + parallel: + matrix: + - DISTRO: [ 'ubuntu focal', 'ubuntu jammy', 'ubuntu noble', 'debian bullseye', 'debian bookworm', 'kali kali-rolling', 'oracle 8', 'oracle 9', 'opensuse 15', 'fedora forty', 'fedora fortyone', 'alpine 318', 'alpine 319', 'alpine 320', 'alpine 321' ] -build_ubuntu_jammy: - stage: build - allow_failure: true +run_test_amd64: + stage: run_test tags: - oci-fixed-amd before_script: - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts script: - - bash builder/build-package ubuntu jammy; + - bash builder/test-barebones --run-test $DISTRO only: variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ "$DISTRO" + dependencies: + - build_amd64 artifacts: - paths: - - output/ + reports: + junit: + - run_test/*.xml + parallel: + matrix: + - DISTRO: [ 'ubuntu focal', 'ubuntu jammy', 'ubuntu noble', 'debian bullseye', 'debian bookworm', 'kali kali-rolling', 'oracle 8', 'oracle 9', 'opensuse 15', 'fedora forty', 'fedora fortyone', 'alpine 318', 'alpine 319', 'alpine 320', 'alpine 321' ] -build_ubuntu_jammy_arm: - stage: build - allow_failure: true +run_test_arm64: + stage: run_test tags: - oci-fixed-arm before_script: - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts script: - - bash builder/build-package ubuntu jammy; + - bash builder/test-barebones --run-test $DISTRO only: variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME + - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ "$DISTRO" + dependencies: + - build_arm64 artifacts: - paths: - - output/ + reports: + junit: + - run_test/*.xml + parallel: + matrix: + - DISTRO: [ 'ubuntu focal', 'ubuntu jammy', 'ubuntu noble', 'debian bullseye', 'debian bookworm', 'kali kali-rolling', 'oracle 8', 'oracle 9', 'opensuse 15', 'fedora forty', 'fedora fortyone', 'alpine 318', 'alpine 319', 'alpine 320', 'alpine 321' ] -build_ubuntu_noble: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package ubuntu noble; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_ubuntu_noble_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package ubuntu noble; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_debian_bullseye: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package debian bullseye; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_debian_bullseye_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package debian bullseye; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - - -build_debian_bookworm: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package debian bookworm; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_debian_bookworm_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package debian bookworm; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_kali_rolling: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package kali kali-rolling; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_kali_rolling_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package kali kali-rolling; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_oracle_8: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package oracle 8; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_oracle_8_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package oracle 8; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_oracle_9: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package oracle 9; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_oracle_9_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package oracle 9; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_opensuse_15: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package opensuse 15; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_opensuse_15_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package opensuse 15; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_thirtynine: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora thirtynine; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_thirtynine_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora thirtynine; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_forty: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora forty; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_forty_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora forty; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_fortyone: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora fortyone; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_fedora_fortyone_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package fedora fortyone; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - - -test: +spec_test: stage: test tags: - kasmvnc-x86 @@ -540,158 +188,6 @@ test: - bash builder/test-vncserver -build_alpine_318: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 318; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_318_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 318; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_319: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 319; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_319_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 319; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_320: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 320; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_320_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 320; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_321: - stage: build - allow_failure: true - tags: - - oci-fixed-amd - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 321; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - -build_alpine_321_arm: - stage: build - allow_failure: true - tags: - - oci-fixed-arm - before_script: - - *prepare_build - - *prepare_www - after_script: - - *prepare_artfacts - script: - - bash builder/build-package alpine 321; - only: - variables: - - $BUILD_JOBS == 'all' || $BUILD_JOBS =~ $CI_JOB_NAME - artifacts: - paths: - - output/ - upload: stage: upload image: ubuntu:focal diff --git a/builder/build-package b/builder/build-package index 598230d..5f142f9 100755 --- a/builder/build-package +++ b/builder/build-package @@ -6,14 +6,7 @@ os="$1" codename="$2" build_tag="$3" -detect_package_format() { - package_format=rpm - if ls builder/dockerfile*"$os"* | grep -q .deb.build; then - package_format=deb - elif ls builder/dockerfile*"$os"* | grep -q .apk.build; then - package_format=apk - fi -} +. ./builder/common.sh warn_build_tag_not_supported_for_rpm_and_exit() { if [[ "$build_tag" && "$package_format" = "rpm" ]]; then diff --git a/builder/common.sh b/builder/common.sh index 50f2c06..83003dc 100644 --- a/builder/common.sh +++ b/builder/common.sh @@ -1 +1,24 @@ VNC_PORT=8443 + +detect_build_dir() { + if [ -n "$CI" ]; then + build_dir=output + else + build_dir=builder/build + fi +} + +detect_interactive() { + if [ -z "$run_test" ]; then + interactive=-it + fi +} + +detect_package_format() { + package_format=rpm + if ls builder/dockerfile*"$os"* | grep -q .deb.build; then + package_format=deb + elif ls builder/dockerfile*"$os"* | grep -q .apk.build; then + package_format=apk + fi +} diff --git a/builder/dockerfile.alpine.barebones.apk.test b/builder/dockerfile.alpine.barebones.apk.test new file mode 100644 index 0000000..061a54f --- /dev/null +++ b/builder/dockerfile.alpine.barebones.apk.test @@ -0,0 +1,24 @@ +ARG BASE_IMAGE +FROM $BASE_IMAGE + +RUN apk add bash + +ENV STARTUPDIR=/dockerstartup + +COPY ./builder/scripts/ /tmp/scripts/ +COPY alpine/kasmvncserver/APKBUILD /tmp + +ARG KASMVNC_PACKAGE_DIR +COPY $KASMVNC_PACKAGE_DIR/kasmvncserver-*.apk /tmp/ +RUN /tmp/scripts/install_kasmvncserver_package + +ARG RUN_TEST +RUN [ "$RUN_TEST" = 1 ] || apk add xterm + +RUN mkdir -p $STARTUPDIR +COPY builder/startup/vnc_startup_barebones.sh $STARTUPDIR + +RUN adduser -D -s/bin/bash foo && addgroup foo kasmvnc-cert +USER foo + +ENTRYPOINT "/$STARTUPDIR/vnc_startup_barebones.sh" diff --git a/builder/dockerfile.alpine_318.barebones.apk.test b/builder/dockerfile.alpine_318.barebones.apk.test new file mode 120000 index 0000000..388647d --- /dev/null +++ b/builder/dockerfile.alpine_318.barebones.apk.test @@ -0,0 +1 @@ +dockerfile.alpine.barebones.apk.test \ No newline at end of file diff --git a/builder/dockerfile.alpine_319.barebones.apk.test b/builder/dockerfile.alpine_319.barebones.apk.test new file mode 120000 index 0000000..388647d --- /dev/null +++ b/builder/dockerfile.alpine_319.barebones.apk.test @@ -0,0 +1 @@ +dockerfile.alpine.barebones.apk.test \ No newline at end of file diff --git a/builder/dockerfile.alpine_320.barebones.apk.test b/builder/dockerfile.alpine_320.barebones.apk.test new file mode 120000 index 0000000..388647d --- /dev/null +++ b/builder/dockerfile.alpine_320.barebones.apk.test @@ -0,0 +1 @@ +dockerfile.alpine.barebones.apk.test \ No newline at end of file diff --git a/builder/dockerfile.alpine_321.barebones.apk.test b/builder/dockerfile.alpine_321.barebones.apk.test new file mode 120000 index 0000000..388647d --- /dev/null +++ b/builder/dockerfile.alpine_321.barebones.apk.test @@ -0,0 +1 @@ +dockerfile.alpine.barebones.apk.test \ No newline at end of file diff --git a/builder/dockerfile.debian.barebones.deb.test b/builder/dockerfile.debian.barebones.deb.test new file mode 100644 index 0000000..927f52d --- /dev/null +++ b/builder/dockerfile.debian.barebones.deb.test @@ -0,0 +1,22 @@ +ARG BASE_IMAGE +FROM $BASE_IMAGE + +ENV STARTUPDIR=/dockerstartup + +COPY ./builder/scripts/ /tmp/scripts/ +COPY ./debian/changelog /tmp + +ARG KASMVNC_PACKAGE_DIR +COPY $KASMVNC_PACKAGE_DIR/kasmvncserver_*.deb /tmp/ +RUN /tmp/scripts/install_kasmvncserver_package + +ARG RUN_TEST +RUN if [ "$RUN_TEST" != 1 ]; then apt-get update && apt-get -y install xterm lsb-release; fi + +RUN mkdir -p $STARTUPDIR +COPY builder/startup/vnc_startup_barebones.sh $STARTUPDIR + +RUN useradd -m foo && adduser foo ssl-cert +USER foo + +ENTRYPOINT "/$STARTUPDIR/vnc_startup_barebones.sh" diff --git a/builder/dockerfile.debian_bookworm.barebones.deb.test b/builder/dockerfile.debian_bookworm.barebones.deb.test new file mode 120000 index 0000000..9ec488c --- /dev/null +++ b/builder/dockerfile.debian_bookworm.barebones.deb.test @@ -0,0 +1 @@ +dockerfile.debian.barebones.deb.test \ No newline at end of file diff --git a/builder/dockerfile.debian_bullseye.barebones.deb.test b/builder/dockerfile.debian_bullseye.barebones.deb.test new file mode 120000 index 0000000..9ec488c --- /dev/null +++ b/builder/dockerfile.debian_bullseye.barebones.deb.test @@ -0,0 +1 @@ +dockerfile.debian.barebones.deb.test \ No newline at end of file diff --git a/builder/dockerfile.fedora_forty.barebones.rpm.test b/builder/dockerfile.fedora_forty.barebones.rpm.test new file mode 100644 index 0000000..de0c4ec --- /dev/null +++ b/builder/dockerfile.fedora_forty.barebones.rpm.test @@ -0,0 +1,25 @@ +FROM fedora:40 + +ENV STARTUPDIR=/dockerstartup + +ARG RUN_TEST +RUN [ "$RUN_TEST" = 1 ] || dnf install -y \ + less \ + redhat-lsb-core \ + vim \ + xterm + +COPY ./builder/scripts/ /tmp/scripts/ + +ARG KASMVNC_PACKAGE_DIR +COPY $KASMVNC_PACKAGE_DIR/kasmvncserver-*.rpm /tmp/ +COPY fedora/kasmvncserver.spec /tmp/ +RUN /tmp/scripts/install_kasmvncserver_package + +RUN mkdir -p $STARTUPDIR +COPY builder/startup/vnc_startup_barebones.sh $STARTUPDIR + +RUN useradd -m foo +USER foo:kasmvnc-cert + +ENTRYPOINT "/$STARTUPDIR/vnc_startup_barebones.sh" diff --git a/builder/dockerfile.fedora_fortyone.barebones.rpm.test b/builder/dockerfile.fedora_fortyone.barebones.rpm.test new file mode 100644 index 0000000..a2b94d1 --- /dev/null +++ b/builder/dockerfile.fedora_fortyone.barebones.rpm.test @@ -0,0 +1,25 @@ +FROM fedora:41 + +ENV STARTUPDIR=/dockerstartup + +ARG RUN_TEST +RUN [ "$RUN_TEST" = 1 ] || dnf install -y \ + less \ + redhat-lsb-core \ + vim \ + xterm + +COPY ./builder/scripts/ /tmp/scripts/ + +ARG KASMVNC_PACKAGE_DIR +COPY $KASMVNC_PACKAGE_DIR/kasmvncserver-*.rpm /tmp/ +COPY fedora/kasmvncserver.spec /tmp/ +RUN /tmp/scripts/install_kasmvncserver_package + +RUN mkdir -p $STARTUPDIR +COPY builder/startup/vnc_startup_barebones.sh $STARTUPDIR + +RUN useradd -m foo +USER foo:kasmvnc-cert + +ENTRYPOINT "/$STARTUPDIR/vnc_startup_barebones.sh" diff --git a/builder/dockerfile.kali_kali-rolling.barebones.deb.test b/builder/dockerfile.kali_kali-rolling.barebones.deb.test new file mode 120000 index 0000000..9ec488c --- /dev/null +++ b/builder/dockerfile.kali_kali-rolling.barebones.deb.test @@ -0,0 +1 @@ +dockerfile.debian.barebones.deb.test \ No newline at end of file diff --git a/builder/dockerfile.opensuse_15.barebones.rpm.test b/builder/dockerfile.opensuse_15.barebones.rpm.test index 3501b64..fa4f435 100644 --- a/builder/dockerfile.opensuse_15.barebones.rpm.test +++ b/builder/dockerfile.opensuse_15.barebones.rpm.test @@ -3,7 +3,8 @@ FROM opensuse/leap:15.5 ENV STARTUPDIR=/dockerstartup # base tools -RUN zypper -n install -y \ +ARG RUN_TEST +RUN [ "$RUN_TEST" = 1 ] || zypper -n install -y \ less \ vim \ xterm @@ -15,7 +16,7 @@ COPY $KASMVNC_PACKAGE_DIR/*.rpm /tmp RUN zypper install -y --allow-unsigned-rpm /tmp/*.rpm RUN mkdir -p $STARTUPDIR -COPY startup/vnc_startup_barebones.sh $STARTUPDIR +COPY builder/startup/vnc_startup_barebones.sh $STARTUPDIR RUN useradd -m foo USER foo:kasmvnc-cert diff --git a/builder/dockerfile.oracle_8.barebones.rpm.test b/builder/dockerfile.oracle_8.barebones.rpm.test index d4cc293..3904e2c 100644 --- a/builder/dockerfile.oracle_8.barebones.rpm.test +++ b/builder/dockerfile.oracle_8.barebones.rpm.test @@ -2,7 +2,8 @@ FROM oraclelinux:8 ENV STARTUPDIR=/dockerstartup -RUN dnf install -y \ +ARG RUN_TEST +RUN [ "$RUN_TEST" = 1 ] || dnf install -y \ less \ redhat-lsb-core \ vim \ @@ -10,12 +11,15 @@ RUN dnf install -y \ RUN dnf config-manager --set-enabled ol8_codeready_builder RUN dnf install -y oracle-epel-release-el8 +COPY ./builder/scripts/ /tmp/scripts/ + ARG KASMVNC_PACKAGE_DIR -COPY $KASMVNC_PACKAGE_DIR/*.rpm /tmp -RUN dnf localinstall -y /tmp/*.rpm +COPY $KASMVNC_PACKAGE_DIR/kasmvncserver-*.rpm /tmp/ +COPY fedora/kasmvncserver.spec /tmp/ +RUN /tmp/scripts/install_kasmvncserver_package RUN mkdir -p $STARTUPDIR -COPY startup/vnc_startup_barebones.sh $STARTUPDIR +COPY builder/startup/vnc_startup_barebones.sh $STARTUPDIR RUN useradd -m foo USER foo:kasmvnc-cert diff --git a/builder/dockerfile.oracle_9.barebones.rpm.test b/builder/dockerfile.oracle_9.barebones.rpm.test index 2e8f3b5..e4fa885 100644 --- a/builder/dockerfile.oracle_9.barebones.rpm.test +++ b/builder/dockerfile.oracle_9.barebones.rpm.test @@ -2,7 +2,7 @@ FROM oraclelinux:9 ENV STARTUPDIR=/dockerstartup -RUN dnf install -y \ +RUN [ "$RUN_TEST" = 1 ] || dnf install -y \ less \ vim \ xterm @@ -17,7 +17,7 @@ RUN dnf install -y crypto-policies-scripts RUN update-crypto-policies --set FIPS:SHA1 RUN mkdir -p $STARTUPDIR -COPY startup/vnc_startup_barebones.sh $STARTUPDIR +COPY builder/startup/vnc_startup_barebones.sh $STARTUPDIR RUN useradd -m foo USER foo:kasmvnc-cert diff --git a/builder/dockerfile.ubuntu_focal.barebones.deb.test b/builder/dockerfile.ubuntu_focal.barebones.deb.test deleted file mode 100644 index d9effe0..0000000 --- a/builder/dockerfile.ubuntu_focal.barebones.deb.test +++ /dev/null @@ -1,20 +0,0 @@ -FROM ubuntu:focal - -ENV STARTUPDIR=/dockerstartup - -COPY ./builder/scripts/ /tmp/scripts/ -COPY ./debian/changelog /tmp - -ARG KASMVNC_PACKAGE_DIR -COPY $KASMVNC_PACKAGE_DIR/kasmvncserver_*.deb /tmp/ -RUN /tmp/scripts/install_kasmvncserver_package - -RUN apt-get update && apt-get -y install xterm lsb-release - -RUN mkdir -p $STARTUPDIR -COPY builder/startup/vnc_startup_barebones.sh $STARTUPDIR - -RUN useradd -m foo && addgroup foo ssl-cert -USER foo - -ENTRYPOINT "/$STARTUPDIR/vnc_startup_barebones.sh" diff --git a/builder/dockerfile.ubuntu_focal.barebones.deb.test b/builder/dockerfile.ubuntu_focal.barebones.deb.test new file mode 120000 index 0000000..9ec488c --- /dev/null +++ b/builder/dockerfile.ubuntu_focal.barebones.deb.test @@ -0,0 +1 @@ +dockerfile.debian.barebones.deb.test \ No newline at end of file diff --git a/builder/dockerfile.ubuntu_jammy.barebones.deb.test b/builder/dockerfile.ubuntu_jammy.barebones.deb.test new file mode 120000 index 0000000..9ec488c --- /dev/null +++ b/builder/dockerfile.ubuntu_jammy.barebones.deb.test @@ -0,0 +1 @@ +dockerfile.debian.barebones.deb.test \ No newline at end of file diff --git a/builder/dockerfile.ubuntu_noble.barebones.deb.test b/builder/dockerfile.ubuntu_noble.barebones.deb.test new file mode 120000 index 0000000..9ec488c --- /dev/null +++ b/builder/dockerfile.ubuntu_noble.barebones.deb.test @@ -0,0 +1 @@ +dockerfile.debian.barebones.deb.test \ No newline at end of file diff --git a/builder/process_test_options.sh b/builder/process_test_options.sh index da8b55c..7f7d659 100644 --- a/builder/process_test_options.sh +++ b/builder/process_test_options.sh @@ -6,7 +6,7 @@ usage() { } process_options() { - local sorted_options=$(getopt -o psh --long perf-test --long shell --long help -- "$@") + local sorted_options=$(getopt -o prsh --long perf-test --long run-test --long shell --long help -- "$@") eval set -- $sorted_options while : ; do @@ -16,6 +16,10 @@ process_options() { entrypoint_executable="--entrypoint=/usr/bin/Xvnc" shift ;; + -r|--run-test) + run_test=1 + shift + ;; -s|--shell) entrypoint_executable="--entrypoint=bash" shift diff --git a/builder/scripts/install_kasmvncserver_package b/builder/scripts/install_kasmvncserver_package index 7537d57..dcdf79c 100755 --- a/builder/scripts/install_kasmvncserver_package +++ b/builder/scripts/install_kasmvncserver_package @@ -10,6 +10,10 @@ is_debian() { [[ -f /etc/debian_version ]] } +is_alpine() { + [[ -f /etc/alpine-release ]] +} + check_package_version_exists() { if ! stat /tmp/kasmvncserver_"$package_version"*.deb; then >&2 echo "No package found for version $package_version" @@ -42,7 +46,16 @@ install_package_built_for_current_branch_package_version_deb() { --file /tmp/changelog) check_package_version_exists - apt-get install -y /tmp/kasmvncserver_"$package_version"*"$tag"*.deb + dpkg_arch=$(dpkg-architecture -q DEB_BUILD_ARCH) + apt-get install -y /tmp/kasmvncserver_"$package_version"*"$tag"*_${dpkg_arch}.deb +} + +detect_dnf_command() { + if command -v dnf5 >/dev/null; then + echo dnf install -y --allowerasing + else + echo dnf localinstall -y --allowerasing + fi } install_package_built_for_current_branch_package_version_rpm() { @@ -50,15 +63,24 @@ install_package_built_for_current_branch_package_version_rpm() { $rpm_package_manager install -y rpmdevtools package_version=$(rpmspec -q --qf '%{version}\n' /tmp/kasmvncserver.spec 2>/dev/null) + package_name=/tmp/kasmvncserver-"$package_version"*.$(arch).rpm if [[ $rpm_package_manager = "dnf" ]]; then - dnf localinstall -y --allowerasing /tmp/kasmvncserver-"$package_version"*.rpm + local dnf_cmd=$(detect_dnf_command) + $dnf_cmd $package_name else - yum install -y /tmp/kasmvncserver-"$package_version"*.rpm + yum install -y $package_name fi } +install_package_built_for_current_branch_package_version_apk() { + package_version=$(sed -n 's/pkgver=\(.\+\)/\1/p' /tmp/APKBUILD ) + apk add /tmp/kasmvncserver-"$package_version"*.apk /tmp/kasmvncserver-doc-"$package_version"*.apk --allow-untrusted +} + if is_debian ; then install_package_built_for_current_branch_package_version_deb +elif is_alpine; then + install_package_built_for_current_branch_package_version_apk else install_package_built_for_current_branch_package_version_rpm fi diff --git a/builder/startup/vnc_startup_barebones.sh b/builder/startup/vnc_startup_barebones.sh index 2fea7f8..8306941 100755 --- a/builder/startup/vnc_startup_barebones.sh +++ b/builder/startup/vnc_startup_barebones.sh @@ -19,4 +19,9 @@ set_xterm_to_run create_kasm_user vncserver -select-de manual -websocketPort "$VNC_PORT" +vncserver_exit_code=$? +if [ "$RUN_TEST" = 1 ]; then + exit "$vncserver_exit_code" +fi + tail -f "$config_dir"/*.log diff --git a/builder/test-apk-barebones b/builder/test-apk-barebones new file mode 100755 index 0000000..945412c --- /dev/null +++ b/builder/test-apk-barebones @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +detect_base_image() { + BASE_IMAGE=$(echo "${os}:${os_codename}" | sed 's/\([0-9]\{2\}\)$/.\1/') +} + +cd "$(dirname "$0")/.." +. ./builder/process_test_options.sh +. ./builder/common.sh +os="${1:-alpine}" +os_codename="${2:-321}" + +detect_build_dir +detect_base_image +docker build --build-arg KASMVNC_PACKAGE_DIR="${build_dir}/${os}_${os_codename}" \ + --build-arg RUN_TEST="$run_test" \ + --build-arg BASE_IMAGE="$BASE_IMAGE" \ + -t kasmvnctester_barebones_${os}:$os_codename \ + -f builder/dockerfile.${os}_${os_codename}.barebones.apk.test . +echo + +detect_interactive +docker run $interactive -p "443:$VNC_PORT" --rm -e "VNC_USER=foo" -e "VNC_PW=foobar" \ + -e "VNC_PORT=$VNC_PORT" \ + -e RUN_TEST="$run_test" \ + $entrypoint_executable \ + kasmvnctester_barebones_${os}:$os_codename \ + $entrypoint_args diff --git a/builder/test-barebones b/builder/test-barebones new file mode 100755 index 0000000..aee9055 --- /dev/null +++ b/builder/test-barebones @@ -0,0 +1,42 @@ +#!/bin/bash + +set -eo pipefail + +create_gitlab_report() { + local error="$1" +failure_report=$(cat < + + + ${error} + + +EOF +) +} + +write_gitlab_report() { + echo "$failure_report" > run_test/"${os}_${os_codename}.xml" +} + +saved_options=("$@") +. ./builder/process_test_options.sh +. ./builder/common.sh + +os="$1" +os_codename="$2" +os_fullname="${os}_${os_codename}" + +detect_package_format +if [ "$run_test" != 1 ]; then + builder/test-${package_format}-barebones "${saved_options[@]}" + exit $? +fi + +mkdir -p run_test +if ! builder/test-${package_format}-barebones "${saved_options[@]}" 2>&1 | \ + tee run_test/"${os_fullname}.log"; then + create_gitlab_report "$(tail -1 run_test/${os_fullname}.log)" + write_gitlab_report + exit 1 +fi diff --git a/builder/test-deb-barebones b/builder/test-deb-barebones index 9ffdb5d..593ce5c 100755 --- a/builder/test-deb-barebones +++ b/builder/test-deb-barebones @@ -2,18 +2,33 @@ set -e +detect_base_image() { + if [ "$os" = kali ]; then + BASE_IMAGE=kalilinux/kali-rolling:latest + return + fi + BASE_IMAGE="${os}:${os_codename}" +} + cd "$(dirname "$0")/.." . ./builder/process_test_options.sh . ./builder/common.sh os="${1:-debian}" os_codename="${2:-buster}" -docker build --build-arg KASMVNC_PACKAGE_DIR="builder/build/${os_codename}" \ +detect_build_dir +detect_base_image +docker build --build-arg KASMVNC_PACKAGE_DIR="${build_dir}/${os_codename}" \ + --build-arg RUN_TEST="$run_test" \ + --build-arg BASE_IMAGE="$BASE_IMAGE" \ -t kasmvnctester_barebones_${os}:$os_codename \ -f builder/dockerfile.${os}_${os_codename}.barebones.deb.test . echo -docker run -it -p "443:$VNC_PORT" --rm -e "VNC_USER=foo" -e "VNC_PW=foobar" \ + +detect_interactive +docker run $interactive -p "443:$VNC_PORT" --rm -e "VNC_USER=foo" -e "VNC_PW=foobar" \ -e "VNC_PORT=$VNC_PORT" \ + -e RUN_TEST="$run_test" \ $entrypoint_executable \ kasmvnctester_barebones_${os}:$os_codename \ $entrypoint_args diff --git a/builder/test-rpm-barebones b/builder/test-rpm-barebones index ea4cae6..1151222 100755 --- a/builder/test-rpm-barebones +++ b/builder/test-rpm-barebones @@ -2,17 +2,22 @@ set -e -cd "$(dirname "$0")" -. ./process_test_options.sh -. ./common.sh +cd "$(dirname "$0")/.." +. ./builder/process_test_options.sh +. ./builder/common.sh os="${1:-oracle}" os_codename="${2:-8}" -docker build --build-arg KASMVNC_PACKAGE_DIR="build/${os}_${os_codename}" \ +detect_build_dir +docker build --build-arg KASMVNC_PACKAGE_DIR="${build_dir}/${os}_${os_codename}" \ + --build-arg RUN_TEST="$run_test" \ -t kasmvnctester_barebones_${os}:$os_codename \ - -f dockerfile.${os}_${os_codename}.barebones.rpm.test . -docker run -it -p "443:$VNC_PORT" --rm -e "VNC_USER=foo" -e "VNC_PW=foobar" \ + -f builder/dockerfile.${os}_${os_codename}.barebones.rpm.test . + +detect_interactive +docker run $interactive -p "443:$VNC_PORT" --rm -e "VNC_USER=foo" -e "VNC_PW=foobar" \ -e "VNC_PORT=$VNC_PORT" \ + -e RUN_TEST="$run_test" \ $entrypoint_executable \ kasmvnctester_barebones_${os}:$os_codename \ $entrypoint_args